开发者

proper link formatting

I am trying to create a link, which will, allow my paginate开发者_如何学God search to go onto the next page of results including the search term in the url

I get the following error with the link I have created

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/dd615/public_html/searchPage.php on line 47

here is the link

echo "<a href='{$_SERVER['PHP_SELF']}?search=$_GET['search']?pagenumber=1'> FIRST </a>";

any help would be greatly appreciated


You need to wrap the second variable as well:

echo "<a href='{$_SERVER['PHP_SELF']}?search={$_GET['search']}&pagenumber=1'> FIRST </a>";

But it would be better to use proper encoding. So try this:

echo '<a href="' . htmlspecialchars($_SERVER['PHP_SELF'].'?search='.urlencode($_GET['search']).'&pagenumber=1') . '"> FIRST </a>';

urlencode is used to encode any character that is inappropriate in a URL query (according to the application/x-www-form-urlencoded type) and htmlspecialchars escapes the HTML special characters.


it's because of special string syntax. You encloded in curly braces $_SERVER['PHP_SELF'] but failed to do the same for the $_GET['search']. Refer to the string syntax manual page, it worth reading

Also note that only one ? character can be in the query string, & should be used as a separator for the rest of the string


The answer to your actual question is that you need you put curly brackets around $_GET['search'] because it's inside of those quotes. So like this:

echo "<a href='{$_SERVER['PHP_SELF']}?search={$_GET['search']}?pagenumber=1'> FIRST </a>";

Also, unrelated to your question, you may want to change the second '?' to '&' like so:

echo "<a href='{$_SERVER['PHP_SELF']}?search={$_GET['search']}&pagenumber=1'> FIRST </a>";

But then again, maybe not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜