简体   繁体   English

PHP Str_replace在大字符串上不起作用

[英]PHP Str_replace not working on large strings

I am using str_replace to format a string with a relatively large (i think) number of characters but it doesnt process the string. 我正在使用str_replace格式化具有相对较大(我认为)字符数的字符串,但它不处理该字符串。 below is my string and the code im using 下面是我的字符串和即时通讯使用的代码

$formlink = str_replace('&stepvars='.$_GET['stepvars'],'',$link);

The string is 1004 characters long 字符串长度为1004个字符

?content=com_motor&folder=same&file=motor_form&step=one&stepvars=VzNOMGNERmRkR2wwYkdVOVBsTmxiR1ZqZENCVWFYUnNaU3h3Y205d2IzTmxjbDl6ZFhKdVlXMWxQVDVOZFdOb2FYSnBMRzkwYUdWeVgyNWhiV1Z6UFQ1VVpYTjBJRTkwYUdWMExHOWpZM1Z3WVhScGIyNWZjSEp2Wm1WemMybHZiajArVjJWaUlFUmxjMmxuYm1WeUxHUmhlVDArTVRjc2JXOXVkR2c5UGs5amRHOWlaWElzZVdWaGNqMCtNakF3TWl4d2FXNWZibTg5UGpFeU16UTFOaXhwWkY5dmNsOXdZWE56Y0c5eWRGOXViejArTmpVME16SXhMR1J5YVhabGNsOXNhV05sYm5ObFgyNXZQVDQyTXpJMU5ERXNlV1ZoY2w5bWFYSnpkRjlrY21sMmFXNW5YMnhwWTJWdWMyVmZhWE56ZFdWa1BUNHlNREEwTEc1MWJXSmxjbDl2Wmw5NVpXRnljMTlrY21sMmFXNW5YMlY0Y0dWeWFXVnVZMlU5UGpVc1pXMWhhV3hmWVdSa2NtVnpjejArYzI1bmRXMXZRR2R0WVdsc0xtTnZiU3h0YjJKcGJHVmZiblZ0WW1WeVBUNHdOelF4TlRJMk15eHdYMjlmWW05NFBUNHhNalUwZEdWemRDeHdiM04wWVd4ZlkyOWtaVDArTVRJMU5EYzRMSFJ2ZDI0OVBrNWhhWEp2WW1rc1pHOWZlVzkxWDE5aGJtUnZjbDloYm5sZmIzUm9aWEpmY0dWeWMyOXVjMTkzYUc5ZmRHOWZlVzkxY2w5cmJtOTNiR1ZrWjJWZmQybHNiRjlrY21sMlpWOTBhR1ZmWTJGeVgxOXpYMTlmYzNWbVptVnlYMlp5YjIxZlpHVm1aV04wYVhabFgzWnBjMmx2Ymw5dmNsOW9aV0Z5YVc1blgyOXlYMkZ1ZVY5d2FIbHphV05oYkY5cGJtWnBjbTFwZEhsZmFXNWpiSFZrYVc1blgyWnBkSE05UGpBc1czeHpkSEF4WFE9PQ%3D%3D&msgvalid=Now_enter_your_vehicle_details

Please assist me as to where Im going wrong. 请帮助我,我在哪里错了。

Thanks 谢谢

What's probably happening is that your URL has escaped characters in it (%3D%3D) and your $_GET is the unescaped characters so they don't match. 可能发生的情况是您的URL中已转义了字符(%3D%3D),而$ _GET是未转义的字符,因此它们不匹配。 str_replace can work on very large strings without a problem. str_replace可以在很大的字符串上正常工作。

If you want to get rid of that value, just do this: 如果要摆脱该值,请执行以下操作:

$query_params = $_GET;
unset($query_params['stepvars']);
$new_link = http_build_query($query_params);

That will work even if the param is the first one (?stepvars=...) 即使参数是第一个参数,它也将起作用(?stepvars = ...)

In the grand scheme of things, that string is not very large and that is unlikely to be the source of the problem here. 在总体方案中,该字符串不是很大,因此不太可能成为问题的根源。

What is far more likely is that the problem is caused by the %3D%3D at the end of the string, which $_GET will translate into == which will cause the string not to match if %3D%3D is what you're looking for. 更可能的是问题是由字符串末尾的%3D%3D引起的,如果%3D%3D是您要使用的字符串,则$_GET将其转换为== ,这将导致字符串不匹配寻找。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM