Page 1 of 1

parsing URLs

Posted: Tue Jun 17, 2003 8:45 am
by dlibby
[Admin Edit: moved from viewtopic.php?t=78]

Can you use this same idea if you are pulling a url out of a database?? I want to see if the url starts with http:// and if it does show it as a link on the screen as it is. But if it doesn't add the http:// to it and then show it as a link on the screen. I have tried several different ways to pull this information from a $row["AgentHomePage"] but it seems to be skipping the else in my If statement. Any help would be greatly appreciated.

Posted: Tue Jun 17, 2003 9:36 am
by twigletmac
Please don't hijack threads, if you have a similar problem or question to someone else please post your own thread and reference (i.e. post a link) to the other thread in it.

Mac

Posted: Tue Jun 17, 2003 10:01 am
by corlando
This statement will check if your url starts with http:// and preappends it if needed

Code: Select all

<?php

$url = ( eregi("^http://", $row["AgentHomePage"]) ) ?  $row["AgentHomePage"] : ("http://" . $row["AgentHomePage"]);


?>

Posted: Tue Jun 17, 2003 11:42 am
by dlibby
Thank-you, Thank-you, Thank-you corlando!!!!

I knew there had to be a more straight forward way of doing this!! Being a newbie, I always seem to go at it from the wrong direction, and this works exactly the way I needed it to!! Thanks again you made my day!!