brianc Posted December 18, 2009 Share Posted December 18, 2009 I'm pulling data from data base. It is website address (outside of main website). But when it is diplayed on the page. The hyperlink shows My web site and then the website pulled from data base. example: http://www.searchobits.com/www.keplingerfuneralhome.com I just want it to show www.keplingerfuneralhome.com HOW CAN I FIX THIS? <tr> <td></td> <td><a class=ls href=<?=$a1[Website]?>>Website</a></td> </tr> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 18, 2009 Share Posted December 18, 2009 www.keplingerfuneralhome.com does not qualify as a proper absolute url it should be http://www.keplingerfuneralhome.com <tr> <td></td> <td><a class=ls href="http://<?=$a1[Website]?>">Website</a></td> </tr> Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 18, 2009 Share Posted December 18, 2009 Where's your code for creating the links? Quote Link to comment Share on other sites More sharing options...
brianc Posted December 18, 2009 Author Share Posted December 18, 2009 It is pulled from a data base that people have posted. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted December 18, 2009 Share Posted December 18, 2009 is every instance the same? will it always look like this: http://www.searchobits.com/www.keplingerfuneralhome.com? <?php $str = str_replace ('http://www.searchobits.com/', '', $row['url']); ?> i'm sure it's not since that information is usually pried from the OP, but assuming it is, something very simple like what i have above would suffice. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted December 18, 2009 Share Posted December 18, 2009 yup Rajiv has the answer. You need to prefix the url with http://. It might be worth you validating URL's to see if they have a scheme using the parse_url function Quote Link to comment Share on other sites More sharing options...
brianc Posted December 18, 2009 Author Share Posted December 18, 2009 The code above that rajivgonsalves supplied works. Provided that when they post their website address they just enter it like this www.example.com if they put the complet address http://www.example.com. Then it has 2 http:'s and doesn't work Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted December 18, 2009 Share Posted December 18, 2009 which is why I suggested using the parse_url function, to check if it has a scheme or not http://www.php.net/parse_url Quote Link to comment Share on other sites More sharing options...
brianc Posted December 18, 2009 Author Share Posted December 18, 2009 Sorry, I guess I don't know how to impliment the parse_url function. I'm a NEWBEE! Quote Link to comment Share on other sites More sharing options...
premiso Posted December 18, 2009 Share Posted December 18, 2009 That is why he posted a reference to the manual for parse_url If you were to click on that link they show an example of usage: Examples Example #1 A parse_url() example <?php $url = 'http://username:password@hostname/path?arg=value#anchor'; print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); ?> The above example will output: Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor ) /path Perhaps reading that / reading through the user comments on that manual page will help you figure it out. You can use that to see if http is in the url, if it is not you add it. Alternatively you can use a stristr to locate if the http:// is in the url (which this can be tricked if there is a query parameter with http://), so I would suggest using the parse_url method. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 18, 2009 Share Posted December 18, 2009 It is pulled from a data base that people have posted. This would be much simpler if you were to post your code. Content does not magically get displayed on a web page just becuase you pulled records from a database. There must be some code that actually "prepares" the HTML code for the links. For example, does the value in the database include the entire link, i.e. everything from the opening A tag to the closing A tag? Or, does the value in the DB only include the URL and you are building the HTML anchor? The answer to that will require different solutions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.