Re: Re: String /pattern formatting extraction question

From: Date: Mon, 10 Apr 2006 13:52:28 +0000
Subject: Re: Re: String /pattern formatting extraction question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-233669@lists.php.net to get a copy of this message
text1 /ptext2 /otext3
Does it always look like that? text1(whitespace)/ptext2(whitespace)/otext3
The ideea is to extract the texts before and between /o and /p. $html = "asdäüü ö ö vf /pxtestxx/ostestss"; eregi("^([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[1] eregi("^(.*)/p([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2] eregi("^(.*)/o([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2] This example works, but I thought there might be a better way to extract the texts, with a single ereg or preg_match. Regards, Andy. ----- Original Message ----- From: "Barry" <barry@flyerheaven.de> To: <php-general@lists.php.net> Sent: Monday, April 10, 2006 4:22 PM Subject: [PHP] Re: String /pattern formatting extraction question
Andy wrote:
Hi to all, I have the following pattern for a string: text1 /ptext2 /otext3
Does it always look like that? text1(whitespace)/ptext2(whitespace)/otext3 Then use explode to create an array from it explode (" ",$stringpattern);
Now, I want to extract the text by "patterns" from this string by the following rule: no pattern -> text1 (what is before /o or /p) /p -> text2 (what is after /p) /o -> text3 (what is after /o)
Here you can use ereg and foreach foreach ($stringpattern as $key => $value) {
    $variable = substr_count("/",$value);
    if ($variable > 0) / has been found now extract the first two chars
} Or something like that ~ -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#233669) next »