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 Link to comment https://forums.phpfreaks.com/topic/26032-get-the-text-between-2-words-in-a-query/ Share on other sites More sharing options...
AbydosGater Posted November 8, 2006 Share Posted November 8, 2006 try reading www.php.net/explode Link to comment https://forums.phpfreaks.com/topic/26032-get-the-text-between-2-words-in-a-query/#findComment-121556 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] Link to comment https://forums.phpfreaks.com/topic/26032-get-the-text-between-2-words-in-a-query/#findComment-121750 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] Link to comment https://forums.phpfreaks.com/topic/26032-get-the-text-between-2-words-in-a-query/#findComment-121773 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] Link to comment https://forums.phpfreaks.com/topic/26032-get-the-text-between-2-words-in-a-query/#findComment-121775 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.