Php code issue

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
mrobert
Forum Newbie
Posts: 1
Joined: Mon Dec 14, 2009 8:10 pm

Php code issue

Post by mrobert »

Hi this is the code of php which i am using

original

value="http://www.abc.com/page/123456"


code:

<?php
$url = $_GET['id'];
echo "value="http://www.abc.com/page/$url";
?>

i want to replace the 123456 everytime so i used this. But this is not working. Anything wrong here?
iamngk
Forum Commoner
Posts: 50
Joined: Mon Jun 29, 2009 2:20 am

Re: Php code issue

Post by iamngk »

You echo statement line is wrong. It is not properly quoted.

Code: Select all

echo "value=\"http://www.abc.com/page/$url\"";
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Php code issue

Post by Griven »

My personal recommendation here is to use single quotes for the PHP echo statements. That way, when you're mixing it with HTML tags that have double quoted attributes, you don't need to throw in those escape characters. You will, however, have to concatenate variables. See the example below.

Code: Select all

$url = $_GET['id'];
echo 'value="http://www.abc.com/page/', $url ,'"';
Post Reply