Re: parsing a string
| From: | M. Sokolewicz | Date: | Wed, 20 Oct 2004 16:55:41 +0000 |
| Subject: | Re: parsing a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199907@lists.php.net to get a copy of this message | ||
Not sure what you want exactly, but here's a way using regexps to retrieve the strings seperatly:
<?php
$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:
<?php
$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 CampusLocation Name which is Bob (Williams) Help?--------------------------------- Do you Yahoo!? vote.yahoo.com - Register online to vote today!