Jump to content

[SOLVED]implode or explode (HELP PLEASE)


kucing

Recommended Posts

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=17053208

if 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
Link to comment
https://forums.phpfreaks.com/topic/31280-solvedimplode-or-explode-help-please/
Share on other sites

[code]<?php

function 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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.