0

I am using str_replace to format a string with a relatively large (i think) number of characters but it doesnt process the string. below is my string and the code im using

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

The string is 1004 characters long

?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

2 Answers 2

4

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. str_replace can work on very large strings without a problem.

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=...)

Sign up to request clarification or add additional context in comments.

1 Comment

Great insight. I'll add that it can happen with files read from disk (not sure why). Reading str_replace("\n", ...) was not working, but str_replace("\\n", ...) when i read from file. This solution guided me on the track
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.