[Solved] How can i decode data from JSON.stringify

[ad_1] Your problem is the invalid JSON text. I’ve made an attempt to fix the json. Be aware, it’s ugly. Very ugly! So, having this as input: $a=”{“LinkedIn /*trimmed data to fit this format*/ Recruiting”}]}”; // you use $a = $_POST[‘LiRecData’]; What I did was try to reconstruct the JSON based on some (few) existing/correct … Read more

[Solved] I need some help on this code [closed]

[ad_1] I’ve added some comments to your ifs to explain them // Extra post classes $PHTclasses = array(); // if iterator is evenly divisible by # columns, or if there is only one column, add “first” if ( 0 === ($woocommerce_loop[‘loop’]) % $woocommerce_loop[‘columns’] || 1 === $woocommerce_loop[‘columns’] ) $PHTclasses[] = ‘first’; // if iterator is … Read more

[Solved] How performing these two function?

[ad_1] Use preg_match to capture them in your functions. Regex for capturing the letters: /([A-Z]+)/i Regex for capturing the numbers: /([0-9]+)/ So you could have functions like: function getAlpha($source) { preg_match(“/([A-Z]+)/i”, $source, $matches); return $matches[1]; } function getNumeric($source) { preg_match(“/([0-9]+)/”, $source, $matches); return $matches[1]; } And you would use it like this: echo getAlpha(“butterfly12”); //butterfly … Read more

[Solved] plain mysql prepare statement prevent injection attack?

[ad_1] [I assume that you meant $mysqli is mysqli connection.] Although the execution of stmt1 (the last of your three queries) is safe, the multi-query function you wrote is very unsafe. Running something like userQuery(“‘; delete from user; select * from user where username=””); will actually delete all users from your user table. Assuming $username … Read more

[Solved] Why is the output Negative? [closed]

[ad_1] Many notations use “^” as a power operator, but in PHP (and other C-based languages) that is actually the XOR operator. You need to use this ‘pow’ function, there is no power operator. In your code $keone = $vone ^ 2; Should be $keone = pow($vone,2); Rest of your code is fine. That pow … Read more

[Solved] Use of global for mysqli_insert_id()

[ad_1] class MySQLiConnection { private static $conn = null; private function __construct() { } public static function getConnection() { if (static::$conn === null) { static::$conn = mysqli_connect(/* your params go here */); } return static::$conn; } } Then you can replace all global $conn with $conn = MySQLiConnection::getConnection() 4 [ad_2] solved Use of global for … Read more

[Solved] Seperating html form from php file

[ad_1] The answer is as given in the comment by brombeer: if(isset($_POST[‘submit’])){ will never be triggered, there is no HTML element with name=”submit” – brombeer [ad_2] solved Seperating html form from php file

[Solved] How to Convert string response to array laravel

[ad_1] You should use json() method or object() method on your response variable. API Reference json method: Get the JSON decoded body of the response as an array or scalar value. object method: Get the JSON decoded body of the response as an array or scalar value. Usage: $response = Http::get(“www.api.com/…”); $decodedBody = $response->json(); OR … Read more

[Solved] Doing Age Calculations via OOP [closed]

[ad_1] You can use the DateTime class to easily manipulate dates. I have put the $dateFormat outside of the method because you could also use that to validate your input in setBirthDate if you saw fit. protected $dateFormat=”m/d/Y”; public function getAge() { // Create a DateTime object from the expected format return DateTime::createFromFormat($this->dateFormat, $this->birthDate) // … Read more

[Solved] Replace value in str [closed]

[ad_1] Use str_ireplace() to replace case insensitive in a string. In your case: EDIT: even better without loop and now your array can contain also lowercase: <?php $str= str_ireplace($arr, array_map(‘strtoupper’,$arr) , $str); ?> (asssuming all values in $arr are upper case as in your example) Adding a fix according to Mark’s note: <?php foreach($arr as … Read more