I am new to php and am trying to write a program. I need help with converting strings. Could some please help me write a function to turn this type of code: <span class="navigation_end"><a href="/5-computers">Computers</a> > <a href="/6-bluetooth-adaptor">Bluetooth Adapter</a> > </span> in to this: Computers > Bluetooth Adapter I have the pusado/java code for it but i need someone to translate it to php publie String toText(String html){ boolean a = false; boolean b = false; string toRet; while (html.length() != 0){ if (!a) { if(next two chars of html != "<a") delete them; else a = ture; } else { if(next two chars of html = "</") add ">" to toRet; a = true; else add char to toRet; } return toRet; }
just do echo '<span class="navigation_end"><a href="/5-computers">Computers</a> > <a href="/6-bluetooth-adaptor">Bluetooth Adapter</a> > </span>' Code (markup):
function string_to_text($string){ preg_match_all("/\<a(.*)\>(.*)\<\/a\>/iU", $string, $matches, PREG_SET_ORDER); foreach($matches as $match){ $res .= "{$match[2]} > "; } return substr($res,0,strlen($res)-6); } $new_var = string_to_text($links); PHP:
I tried to test the code and it gives an error. I think there is something wrong with in the pattern but i cant figure it out. http://codepad.org/57KqFEtN
i found this: http://drupal.org/node/17271 its the same error, i dont know if thats your case it work fine on my computer PHP Version 5.2.6 PCRE (Perl Compatible Regular Expressions) Support enabled PCRE Library Version 7.6 2008-01-28 Code (markup): i think your php dont have pcre support, and i dont know what to do in that case sorry