anarchoi Posted November 3, 2006 Share Posted November 3, 2006 hi,I have a query that gets the text of a row in a table and echo it...The text in the table looks like something like this:bla bla text bla bla <yo> text text <yo2> bla bla textHere's what i want to do:Get the text ONLY between <yo> and <yo2> and put it in a variable Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 8, 2006 Share Posted November 8, 2006 try reading www.php.net/explode Quote Link to comment Share on other sites More sharing options...
sasa Posted November 8, 2006 Share Posted November 8, 2006 try[code]<?php$test ='bla bla text bla bla <yo> 1st texr <yo2> bla bla textbla bla text bla bla <yo> 2nd text <yo2> bla bla textbla bla text bla bla <yo> 3rd text <yo2> bla bla text';$a = preg_split('/<yo>/',$test);for ($i = 1; $i < count($a); $i++) { $b = preg_split('/<yo2>/',$a[$i]); $c[] = $b[0];}print_r($c);?>[/code] Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted November 8, 2006 Share Posted November 8, 2006 Here is a call-able function[code]function get_string_between($string, $start, $end) { $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) { return ""; } $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len);}[/code] Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 8, 2006 Share Posted November 8, 2006 [code=php:0]<?php$string = "bla bla text bla bla <yo>text text<yo2> bla bla textbla bla text bla bla <yo>some more text<yo2> bla bla text";preg_match_all('/(?<=<yo>).*?(?=<yo2>)/s', $string, $matches);$matches = $matches[0];print_r($matches);?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.