parsing URLs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dlibby
Forum Newbie
Posts: 3
Joined: Fri May 02, 2003 12:35 pm

parsing URLs

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
corlando
Forum Newbie
Posts: 21
Joined: Sun Jun 15, 2003 10:07 pm

Post 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"]);


?>
dlibby
Forum Newbie
Posts: 3
Joined: Fri May 02, 2003 12:35 pm

Post 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!!
Post Reply