Ad:
 
  • PHP Discussion Thread
  • Unsolved
  • Views: 1057
  • PHP RSS
Similar Threads
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 9:28 am. Reason: i forgot...
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 9:26 am.
Reputation Points: 10
Solved Threads: 7
Light Poster
raju_boini525 is offline Offline
44 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 10: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 1:03 am.
Reputation Points: 153
Solved Threads: 229
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,398 posts
since May 2008
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
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC