html - Cut a string into different sections in PHP? -


I'm quite new to PHP and I have a string ragging in some sections based on price, not that character count.

I've heard of explosion and substrings, but I do not know what I want.

I have an output string:
name: example email: eg@example.com website: http://examples.com/ comment: this is where the comment goes , We can not use the explosion because there are many spaces here, another comment: this is another comment, some random information: this is more information ...

I I want to display information in different lines for beauty purposes.

Is there a way to return a word after a specific word but before another specific word?

You can use regular expressions to obtain it, provided the given string is Always in a regular format

  $ arr = preg_split ('/ (? = [A-Z]) / ', $ Str, -1, PREG_SPLIT_NO_EMPTY);  

Immediately after any uppercase letter, use the expression given on a given string on a regular basis.

If we do print_r () on the array, you can see the following output:

  Array ([0] = & gt; Name: Example [1] = & gt; Email: eg@example.com [2] = & gt; Website: http://examples.com/ [3] = & gt; NOTE: This is where the comment goes ... [4] => Another comment: this is another comment [5] = & gt; some random information: this is more information ...)  

How can you get this string in the first place? If this is something in your control, then I recommend using strongly JSON or similar to transfer data. It's easy and fewer buggy - and you can make sure that it works.


Comments