Forum Moderators: coopster

Message Too Old, No Replies

Stripping http:// form a Url when displaying to a page...

         

sauce

10:23 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Hi I'm trying to display URL's in my link exchange like google does.

Here is the function to display the Link, Description and URL:

$linkshtml .= "<p><a href=\"".$link->url."\" $nwin>".$link->title."</a>$prhtml<br>\n<span class=\"linkdescription\">".$link->description."</span><br><span class=\"url\">".$link->url."</span></p>\n\n";

All the URL's are entered in the database as http://www.example.com but I want them displayed like www.example.com on the site...

Any ideas?

ty

[edited by: jatar_k at 10:26 pm (utc) on June 16, 2005]

Birdman

10:48 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simplest way would be to use the str_replace() function, replacing http:// with a blank string.

$display_link = str_replace( 'http://', '', $link->url );

$linkshtml .= '<p><a href="'.$link->url.'" $nwin>'.$link->title.'</a>$prhtml<br>\n<span class="linkdescription">'.$link->description.'</span><br><span class="url">'.$display_link.'</span></p>\n\n';

Regards,
Birdman

PS. It's nice to use single quotes to surround html strings, because it eliminates the need to escape your double quotes within those strings.

sauce

11:06 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Worked like a charm! Thanks Birdman!

Something so simple that gets you so frustrated... I hate that!

One more thing... is the an easy to strip the rest of the url after the .com ex: www.domain.com/dir/file.html and make it: www.domain.com?

jatar_k

11:13 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could look at the parse_url function [php.net]