How to use ampersands in PHP GET URL variable (or function argument)?

懵懂的女人 提交于 2019-12-17 20:55:00

问题


I've got the following code (this is WordPress function) (example of wrong structure):

<?php paginate_comments_links('prev_text=&#x2190;&nbsp;Older&next_text=Newer&nbsp;&#x2192;'); ?>

Example of correct structure:

<?php paginate_comments_links('prev_text=Older&next_text=Newer'); ?>

As you can see I'm trying to add preceding arrow + space (&#x2190;&nbsp;) to 'Older' word and space + arrow (&nbsp;&#x2192;) to 'Newer' word. The problem is that there is a conflict between & that separates 2 function arguments and & that is the beginning of HTML character.

How should correct structure look like?


回答1:


In case someone searches for the same question:

In order to pass a parameter with ampersands (&), you need to encode it.

use urlencode()

Source : http://php.net/manual/en/function.urlencode.php


To decode it afterward, use: urldecode()

Source : http://php.net/manual/en/function.urldecode.php



来源:https://stackoverflow.com/questions/9488953/how-to-use-ampersands-in-php-get-url-variable-or-function-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!