I could not convert the JSON string to array using PHP. Here is my code: $edu=$_POST[‘edu’]; echo ($edu); The above line is giving the below output. ‘[{“uname”:”univ1″,”year”:”2017″,”description”:”…
Tag: string
remove part of string after delimiter in php
I have seen other I have a string ” cccc cccc – fff” I need to return “cccc cccc” I don’t need to delimiter too I tried to echo the result of substr($mystring , 0, strpos($mystring , “-“)); but it return nothing I also tried resulted returned the main string and…
PHP split comma-separated values but retain quotes
I’m trying to split a string that contains comma-separated set of values. This can be achieved simply by using str_getcsv but I have an additional requirement where it falls short of. I need to retain …
Trim symbol and decimal value from currency string
I have currency input strings like these. $50 …I only need 50 $60.59 …I only need 60, need to remove $ and .59 €360 …I only need 360 €36.99 …I only need 36, need to remove € and .99 £900 …I only need 900 £90.99 …I only need 90 In other words, I need to remove all currency s…
Php base base64 encode and decode not working correctly
I want to encode and decode in php using base64, but the encode and decode function does not give me correct output. I am using code from online php functions. I encode this string “best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي” and get the output: “YmVzdCBhcm…
Find known string in file then add string prior to it
I need to find a known string inside a config file and then add some content(another string) prior to this. What is the most efficient way to do this? Example: filetomodify.config Desired outcome: I’ve been using fopen to access the file but this only allows to prepend or append content, by default with…
Is LEFT JOINING two tables with no reference to each other ON string conditions a bad idea?
I’m migrating database between 2 systems using PHP and MySQL. In the old one I have 3 tables of interest: t1 id (int) … t2 id (int) t1_id (int) d (string) … t3 id (int) t1_id (int) ds (string) e (int) … In the new one I have only t1 and t2 t2.d can have e.g. “abc” or “…
Parse and reformat text with optionally occurring trailing characters
Due to horrible and inconsistent formatting by a certain website we are receiving data from, I need to parse the following string and print new strings after replacing/removing one or two substrings. Desired result: How can I parse a line with two ‘-‘ into the corresponding Owner: name format? My …
Visually same string gives different var_dumps in php
UPDATE: Anwer is here PHP unserialize fails with non-encoded characters? I’m trying to match objects with in_array. This works fine except for the object with this string as a property. Visually they are the same, but when I do a var_dump PHP sees different lengths. var_dump results: What can be the cau…
Replace multiple dashes with one dash
I have a string which looks like this: I want to replace the multiple dashes with a single one. So the expected output would be: I tried to use str_replace(), but I have to write the code again for every possible amount of dashes. So how can I replace any amount of dashes with a single one? For Rizier: Tried: