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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.