Re: Re: parsing a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I tried the print_r on $res.  The preg_match does the first set fine.
So I get:
 
Campus
Bob (Williams)
 
the second one starts 
-----
Address||||||||123 Main St
-----
City||||||||Oxford
 
 
and so on
tularis@xxxxxxxxxxxx wrote:
preg_match('#([^|]*)[|]+([^|]*)~[\\]+(([^\\]*)~[\\]+)+#Ui', $string, $res);
use print_r on the $res to check for the results (I'm not 100% sure if
they'll come out in $res[2], $res[3], $res[4], etc. or in $res[4][0],
$res[4][1], etc.


> I knew I shouldnt have abreviated the string.
> here is the string sorry I kinda flubbed on the last string
> "Location||||||||Campus~\\\\\\\\\\n-----\nName||||||||Bob
> Williams~\\\\\\\\\\n-----\nAddress||||||||123 Main
> St~\\\\\\\\\\n-----\n..."
>
> the ... is a very long list.
>
> how does this change the preg_match
>
> "M. Sokolewicz" wrote:
> Not sure what you want exactly, but here's a way using regexps to
> retrieve the strings seperatly:
> $string = 'Campus||||||||Bob (Williams)~\\\\\\\\\toms more
> crap)~\\\\\\\\\blah blah blah)~\\\\\\\\\';
> preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui',
> $string, $res);
> $campus = $res[1];
> $bob = $res[2];
> $crap = $res[3];
> $blah = $res[4];
> ?>
> Now, if you wanted the positions... then something like this would work:
>
> $string = 'Campus||||||||Bob (Williams)~\\\\\\\\\toms more
> crap)~\\\\\\\\\blah blah blah)~\\\\\\\\\';
> preg_match('#([^|]*)[|]+([^|]*)~[\]+([^\]*)~[\]+([^\]*)~[\]+#Ui',
> $string, $res);
>
> $campus = strpos($string, $res[1]);
> $bob = strpos($string, $res[2]);
> $crap = strpos($string, $res[3]);
> $blah = strpos($string, $res[4]);
> ?>
>
> Dan McCullough wrote:
>> Hey everyone
>>
>> Having a bit of trouble with something.
>>
>> I have a string which has known patterns.
>>
>> $string"Campus||||||||Bob (Williams)~\\\\\\\\\toms more
>> crap)~\\\\\\\\\blah blah blah)~\\\\\\\\\";
>>
>> What I am looking for is
>>
>> Location which is Campus
>> Location Name which is Bob (Williams)
>>
>> Help?
>>
>>
>>
>> ---------------------------------
>> Do you Yahoo!?
>> vote.yahoo.com - Register online to vote today!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --------------------------------------------------------
> "Theres no such thing as a problem unless the servers are on fire!"
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail - Helps protect you from nasty viruses.



--------------------------------------------------------
"Theres no such thing as a problem unless the servers are on fire!"

		
---------------------------------
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux