942,526 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1084
  • PHP RSS
Jul 5th, 2010
0

URL in PHP

Expand Post »
I need a help here, There's an error every time I add a link in my php file.
Example:

PHP Syntax (Toggle Plain Text)
  1. <php
  2. $link = "twitter.com";
  3. echo "<a href = '".$link."'> link </a>";
  4. ?>

on click, the address would be change on "http://localhost/project/twitter.com" whch is supposed to be "twitter.com"
I've tried placing

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $link = "twitter.com";
  3. echo "<a href = '../../".$link."'> link </a>";
  4. ?>

but still it doesn't work. $link is stored in the database.
I'm new here. Please help me.
Last edited by helpmmeworld; Jul 5th, 2010 at 10:28 am. Reason: i forgot...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
helpmmeworld is offline Offline
1 posts
since Jul 2010
Jul 5th, 2010
0
Re: URL in PHP
try like this
PHP Syntax (Toggle Plain Text)
  1. $link = "www.twitter.com";
  2. <a href ="<?=$link?>"> link </a>
Last edited by raju_boini525; Jul 5th, 2010 at 10:26 am.
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
raju_boini525 is offline Offline
53 posts
since Aug 2009
Jul 5th, 2010
0
Re: URL in PHP
That happens because if you don't put a protocol in a link it will be interpreted as a subdirectory so if you want to make an external link you should put
PHP Syntax (Toggle Plain Text)
  1. http://|https://|ftp://
etc so in your case it would be
PHP Syntax (Toggle Plain Text)
  1. $link = "http://www.twitter.com";
  2. <a href ="<?=$link?>"> link </a>
Last edited by ax8l; Jul 5th, 2010 at 11:35 am.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
ax8l is offline Offline
10 posts
since May 2009
Jul 6th, 2010
0
Re: URL in PHP
You can try these kind of things without www. or http:// in your browser but not with the codes, code strictly first refers to your local. So that only it retrieves your php localhost and tried from there.
Last edited by rajarajan07; Jul 6th, 2010 at 2:03 am.
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Apache cannot run in Win7
Next Thread in PHP Forum Timeline: Indian date-time function plz?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC