如何在PHP中使用&符号GET URL变量(或函数参数)? [英] How to use ampersands in PHP GET URL variable (or function argument)?

查看:162
本文介绍了如何在PHP中使用&符号GET URL变量(或函数参数)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码(这是WordPress的功能)(错误结构的例子):

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

正确结构的示例:

 <?php paginate_comments_links('prev_text =更旧& next_text =更新'); ?> 

正如您看到的,我正在尝试添加之前的箭头+空格( &#x2190;& nbsp; )更改为'旧'字和空格+箭头(& nbsp;&#x2192; )到'更新'一词。问题在于&分离出2个函数参数和&这是HTML字符的开始。



正确的结构应该如何?

解决方案 div>


如果有人搜索相同的问题:

为了传递一个参数(& amp;),你需要对它进行编码。



使用 urlencode()



资料来源: http://php.net/ manual / en / function.urlencode.php






为了解码它,
使用: urldecode()



来源: http://php.net/manual/en/function.urldecode.php


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?

解决方案

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

这篇关于如何在PHP中使用&符号GET URL变量(或函数参数)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆