GuitarGod Posted September 30, 2006 Share Posted September 30, 2006 Hello :DMy question is very similar to a BBcode thing. It's kinda hard to explain so i'll do my best ;). Lets say for example i have a string containing:[code][quote]blahblah[/quote][/code]How would i use PHP to look for the [ quote] and [/ quote], more importantly how can i also get the value between these tags (in this case the 'blahblah'). I suck at explaining PHP problems, so sorry if you don't understand ;) Link to comment https://forums.phpfreaks.com/topic/22572-how-would-i-go-about-doing-this/ Share on other sites More sharing options...
intrik Posted September 30, 2006 Share Posted September 30, 2006 Try using http://au.php.net/str_replace Link to comment https://forums.phpfreaks.com/topic/22572-how-would-i-go-about-doing-this/#findComment-101286 Share on other sites More sharing options...
GuitarGod Posted September 30, 2006 Author Share Posted September 30, 2006 yeah, but i was also thinking along the lines of:[code][quote="Username"]TEXT[/quote][/code]I'm not sure whether str_replace could do this, could it? Link to comment https://forums.phpfreaks.com/topic/22572-how-would-i-go-about-doing-this/#findComment-101291 Share on other sites More sharing options...
Barand Posted September 30, 2006 Share Posted September 30, 2006 try[code]<?phpfunction extractText ($str, $bb='', $startpos=0) { $find = '[' . $bb; $p1 = strpos($str,$find,$startpos); // start of open tag if ($p1===false) return $str; $p2 = strpos($str, ']', $p1); // end of open tag $find = '[/' . $bb; $p3 = strpos($str, $find, $p2); // start of close tag $res = $p3 ? substr($str, $p2+1, $p3-$p2-1) : substr($str, $p2+1); if (!$bb) return extractText($res); else return $res; }$txt = '[quote="Username"][B]TEXT[/B][/quote]';echo extractText($txt, 'quote'); //--> [B]TEXT[/B]echo extractText($txt, 'B'); //--> TEXTecho extractText($txt); //--> TEXT?>[/code] Link to comment https://forums.phpfreaks.com/topic/22572-how-would-i-go-about-doing-this/#findComment-101303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.