[英]php preg_match get everything after match in string
Looking for how to get the complete string in a URI, after the away?to= 寻找离开后如何获取URI中的完整字符串?
My code: 我的代码:
if (isset($_SERVER[REQUEST_URI])) {
$goto = $_SERVER[REQUEST_URI];
}
if (preg_match("/to=(.+)/", $goto, $goto_url)) {
$link = "<a href='{$goto_url[1]}' target='_blank'>{$goto_url[1]}</a>";
The original link is: 原始链接是:
https://domain.com/away?to=http://www.zdf.de/ZDFmediathek#/beitrag/video/2162504/Verschw%C3%B6rung-gegen-die-Freiheit-%281%29
.. but my code is cutting the string after the away?to= to only ..但我的代码是在走远之后将字符串切掉?
http://www.zdf.de/ZDFmediathek
You know the fix for this preg_match function to allow really every character following the away?to= ?? 您知道此preg_match函数的修复程序,它允许真正的每个字符跟随走?
UPDATE: 更新:
Found out, that $_SERVER['REQUEST_URI']
or $_SERVER['QUERY_STRING']
is already cutting the original URL. 发现, $_SERVER['REQUEST_URI']
或$_SERVER['QUERY_STRING']
已在切割原始URL。 Do you know why and how to prevent that? 您知道为什么以及如何预防吗?
try use (.*)
to get all after to=
尝试使用(.*)
来获取所有后缀to=
$str = 'away?to=dfkhgkjdshfgkhldsflkgh';
preg_match("/to=(.*)/", $str, $goto_url);
echo $goto_url[1]; //dfkhgkjdshfgkhldsflkgh
不用从请求URI中使用正则表达式提取URL,您只需从$ _GET数组中获取即可:
$link = "<a href='{$_GET['to']}' target='_blank'>{$_GET['to']}</a>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.