Page 1 of 1

preg_split help needed

Posted: Mon Mar 27, 2006 10:29 am
by maxjac
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.

Posted: Mon Mar 27, 2006 10:54 am
by Chris Corbyn
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);

Posted: Mon Mar 27, 2006 1:30 pm
by maxjac
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...

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);
What could be the problem ?

Thanks again :)
Maxjac