BSlepkov Posted December 3, 2008 Share Posted December 3, 2008 The answer may be so simple that I've totally overlooked it, but I've been struggling to use preg_match with strrpos. Can it be done? If so, my coding would be a heck of a lot more efficient and elegant. Basically, what I want to do is extract the first specific tag (<tr ... > or <li ... >) to the left of a string. The problem is not my regular express (#<(tr|li)[^<]*?>#i), just getting something like ... strrpos($some-xhtml-text, preg_match('#<(tr|li)[^<]*?>#i', $some-xhtml-text, $tag)); ... to work. Any takers? Quote Link to comment https://forums.phpfreaks.com/topic/135337-using-preg_match-with-strrpos/ Share on other sites More sharing options...
.josh Posted December 3, 2008 Share Posted December 3, 2008 since when is nesting functions elegant? And anyways, that won't work, because preg_match returns the results in an array specified in the 3rd argument. When you try to assign preg_match to something, it just assigns 1 for success, 0 for fail. Quote Link to comment https://forums.phpfreaks.com/topic/135337-using-preg_match-with-strrpos/#findComment-704936 Share on other sites More sharing options...
Psycho Posted December 3, 2008 Share Posted December 3, 2008 Why don't you provide a couple examples of input text and the expected output with an explanation of how the output is to be derived. Quote Link to comment https://forums.phpfreaks.com/topic/135337-using-preg_match-with-strrpos/#findComment-704942 Share on other sites More sharing options...
sasa Posted December 3, 2008 Share Posted December 3, 2008 <?php $text = '<tr>'; $big_number = strlen($text); $res = ($x = min(($b = strpos($text, '<li'))===false ? $big_number:$b,($b = strpos($text, '<tr'))===false ? $big_number:$b))== $big_number ? false : $x; echo var_dump($res); ?> Quote Link to comment https://forums.phpfreaks.com/topic/135337-using-preg_match-with-strrpos/#findComment-705081 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.