0

Hi, this is probably very easy for someone, I have a link that I am creating dynamically. There is no problem if I use a static link but when I try to make it dynamic, I get syntax errors. I am not really a php developer. If someone could help I would appreciate it. Code below:

echo '<li>'."<a href='p1/?ID="$_GET['ID']"&page="$value"'>".$value.'</a>'.'</li>';

Not sure where to put single/double quotes or if they are needed at all. Trying to use a url variable as part of the link. But as soon as I put the $_GET in, that's where I get the syntax error.

thank you for your time.

4
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by diafol
2

How php string works??
In php you can give single quote or double quote for defining string.
If you start with single quote, php will find next single quote for completion of it.In middle you can also use double quote.
Dot(.) is used for two string concatenation.
Same for double quote. If you want to use double quote inside two double quote you can use back slash.
e.g.

'Hi I" am '.'php developer' => valid
'Hi I" am '."php developer" => valid
'Hi I' am '."php developer" => Not valid
'Hi I\' am '."php developer" => valid
'Hi I am '."<a href="http://php.net">php</a> developer" => Not valid
'Hi I am '."<a href=\"http://php.net\">php</a> developer" => Valid

Even if you are using dream-weaver like editor proper string always give red color.
If something is messy, based on color highlighting you can recognize it.

Edited by vibhaJ: n/a

Votes + Comments
Thank you so much
good examples
0

try this, let me know if theres an error

echo '<li><a href="p1/?ID='.$_GET['ID'].'&page='.$value.'">'.$value.'</a></li>';

This worked perfect, I knew that you concatenated strings using dot syntax, but I am still a little confused why I had to in this string. Is it because the the $_GET function required single quotes in the brackets?

These type syntax issues tend to hold me up.

0

How php string works??
In php you can give single quote or double quote for defining string.
If you start with single quote, php will find next single quote for completion of it.In middle you can also use double quote.
Dot(.) is used for two string concatenation.
Same for double quote. If you want to use double quote inside two double quote you can use back slash.
e.g.

'Hi I" am '.'php developer' => valid
'Hi I" am '."php developer" => valid
'Hi I' am '."php developer" => Not valid
'Hi I\' am '."php developer" => valid
'Hi I am '."<a href="http://php.net">php</a> developer" => Not valid
'Hi I am '."<a href=\"http://php.net\">php</a> developer" => Valid

Even if you are using dream-weaver like editor proper string always give red color.
If something is messy, based on color highlighting you can recognize it.

Thank you for your reply. Yes, dreamweaver was helping but not giving a solution. I knew about the dot syntax but still a little confused why I had to use it here. Why wouldn't that process as one long string, because of the single quotes inside the $_GET function?

Thank you again.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.