kucing Posted December 19, 2006 Share Posted December 19, 2006 Dear friends,I am having trouble solving this matter..[color=red]If someone help me how to get data like this one:[/color]aUtobiOgraphY, he wasn't, miLk shaKe, oVer driVe, losE mY breAth[color=red]Into this:[/color][url=http://aUtobiOgraphY]aUtobiOgraphY[/url], [url=http://he wasn't]he wasn't[/url], [url=http://miLk shaKe]miLk shaKe[/url], [url=http://oVer driVe]oVer driVe[/url], [url=http://losE mY breAth]losE mY breAth[/url]I saw many sites has this, like eg: http://www.friendster.com/user.php?uid=17053208if you look into "Favorite Movies"And ya I has some result but it only works when I do output using print command but when i try to get result using tpl .. i only get "Array" and nothing else Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 19, 2006 Share Posted December 19, 2006 This is just an example:[code]$strings = array("aUtobiOgraphY", "he wasn't", "miLk shaKe", "oVer driVe", "losE mY breAth");foreach($strings as $string){ echo'<a href="http://mysite.com/'.$string.'">'.$string.'</a>';}[/code] Quote Link to comment Share on other sites More sharing options...
esukf Posted December 19, 2006 Share Posted December 19, 2006 [code]<?phpfunction string_to_links($string, $url){ $string_array = array(); $link_str = ''; $string_array = explode(", ", $string); $count = count($string_array); for($i=0; $i < $count; $i++) { //replace non alphanumeric with spaces $valid_url_str = preg_replace('/\W/', ' ', $string_array[$i]); //build links and replace spaces with underscore $link_str .= '<a href="'.$url.str_replace(' ', '_', $valid_url_str).'">'.$string_array[$i].'</a>'; if($i < ($count-1)) { $link_str .= ', '; } } return $link_str;}$string = "aUtobiOgraphY, he wasn't, miLk shaKe, oVer driVe, losE mY breAth";$url = 'http://www.example.com/test.php?id=';echo string_to_links($string, $url);?>[/code] Quote Link to comment Share on other sites More sharing options...
kucing Posted December 20, 2006 Author Share Posted December 20, 2006 Thanks everyone to help me :) 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.