Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have this string
"{"(2,\"B - Tuna rungu\")","(8,\"C1 - Tuna grahita ringan\")"}"
and I wan't to convert this to PHP array, How do I do that in PHP? Is there any built in class that I can use for this?
the array of this string in PHP should be:
[[2,"B - Tuna rungu"], [8,"C1 - Tuna grahita ringan"]]
There is no class that you can use. You can try some simple string replaces but this is not really stable:
"{" -> [
"}" -> ]
etc.
But what is if you had "{" as proper value in a text field? The correct way is to create a parser/lexer for the syntax of the given string. But for this you need a complete defined syntax with all special cases.
Some information about this:
http://www.codediesel.com/php/building-a-simple-parser-and-lexer-in-php/
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I would like to extract a JSON string within another string.
Currently I am getting the full string using file_get_contents and running the following pattern on the string: https://regex101.com/r/5jAucO/1
which pretty much gives multiple matches.
I would like to extract the JSON string that is saved in window._sharedData but haven't been able to achieve that. Does someone have any idea how I could do that?
Why not include _sharedData in the regex like?
_sharedData\s*=\s*\{.+\}
or with lookbehind:
(?<=_sharedData\s=)\s*\{.+\}
or take the json from a capturing group:
_sharedData\s*=\s*(\{.+\})
One concern with the lookbehind is if they add an additional whitespace character between _sharedData and = it won't match.
This only works well since there are no linebreaks in the JSON.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Fatal error: Hmm - depth calc wrong, hit negatives, in silverstripe after doing a dev/build, it also says /htdocs/framework/core/manifest/ConfigStaticManifest.php on line 278?
Check for program structure whenever you see this kind of error in Silverstripe, make sure it's a valid PHP program, for example make sure all parenthesis and curly braces are properly closed.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to use PHP to find a value in a string and replace it with another value, the value may be (for example) £x on one line and £x.xx on the next, but will always be replaced by a value of £x.xx. Hope that makes sense? TIA.
Use this regex to match the prices: £[0-9]+\.?[0-9]{0,2}
You can perform the replace with this by using this function:
preg_replace("/£[0-9]+\.?[0-9]{0,2}/", " ** REPLACEMENT ** ", $input_lines);
The nice thing about preg_replace is that if you feed it a single line you'll get a single value back, but if you feed it an array of strings with the values you want changed it will return an array with those values replaces. Nice and tidy if you need to make a lot of replacements.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to clean my entries that look like
“If you think adventure is dangerous, try routine; it is lethal.”
<p>Life isn't about finding yourself it's about creating yourself. </p>
I need to remove HTML tags and double quotes and single quotes if they are in the beginning or the end of the string.
There was a function, but I don't remember what it was or something like a class...
You can remove everything with ^[“"'‘]|[”"'’]$|^<[^>]*?>|<[^>]*?>$
Here is a demo.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I would like to split a string from a whole string which has two delimiters. For example
String1= ABC*WELCOME*CDF
I should get out put as WELCOME.
Note: Delimiters can be any position of the string(not static) but I need only string between those two delimiters
Thanks in advance.
$String1 = 'ABC*WELCOME*CDF';
list( ,$myString, ) = explode('*',$String1);
echo $myString;