I have the following dynamic string:
Jacques, P</div><div class="text" style="line-height:13pt;">2789 Henri Cyr<br>Saint Hubert, QC J0Y 5N6
I need to split it to the different dynamic parts that I highlighted in bold:
-> Jacques
-> P
-> 2789
-> Henri Cyr
-> Saint Hubert
-> QC
-> J0Y 5N6
The HTML code in the string will always be there and therefore can be used as the delimiters for the preg_split function but I was never able to get it to work.
Thanks for your time and help is greatly appreciated.
Maxjac.
preg_split help needed
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Jacques, P</div><div class="text" style="line-height:13pt;">2789 Henri Cyr<br>Saint Hubert, QC J0Y 5N6
Code: Select all
preg_match('@>(\w+), (\w+)</div><div class="text" style="line-height:13pt;">(\d+) ([\w ]+)<br>([\w ]+), ([A-Z]+) ([A-Z0-9 ]+)@is', $string, $matches);
print_r($matches);Hello and thanks for you help d11wtq !
I have tried what you suggested but the output is
Array ()
I have pasted the code from your reply and changed '$string' to my variable name...
I even changed my variable to the exact text I had posted on the forum to make sure it's not my code that changes something...
What could be the problem ?
Thanks again
Maxjac
I have tried what you suggested but the output is
Array ()
I have pasted the code from your reply and changed '$string' to my variable name...
I even changed my variable to the exact text I had posted on the forum to make sure it's not my code that changes something...
Code: Select all
$myLine = 'Jacques, P</div><div class="text" style="line-height:13pt;">2077 Henri Cyr<br>Saint Hubert, QC J3Y 8N6';
preg_match('@>(\w+), (\w+)</div><div class="text" style="line-height:13pt;">(\d+) ([\w ]+)<br>([\w ]+), ([A-Z]+) ([A-Z0-9 ]+)@is', $myLine, $matches);
print_r($matches);Thanks again
Maxjac