?mr1=60,60,60,60,60&mr2=90,90,9&0,90,90&mr3=30,30,30,30,30
from the URL it should remove & ifit is there inbetween numbers(ie 90,90,9&0,90,90) and ignore this & if it is there like(60,60,60,60,60&mr2 ).

if after & mr2 or mr1 or mr3 then it should take the param value ,if it is inbetween should remove & only
how to use strpos() for this scenario.
can anyone help me to solve this.

Recommended Answers

All 4 Replies

I assume these are GET arguments from a browser URL? If so, then each of mr1, mr2, and mr3 content strings would be avaliable in your PHP $_GET variables. So $_GET["mr1"] would return '60,60,60,60,60'. Anyway, show your code.

Member Avatar for diafol

Why is your site throwing out misformed url parameters in the first place? Misformed urls should only really come from direct maniulation by the user. Trying to rectify misformed params is a bit pointless:

Validate the params - if they pass great, if not, let 'em know: "Stop being a dick with the url". :)

thanks, this is for manual testing before separating the param values i have to remove & in values.
i have to remove only
?mr1=60,60,60,60,60&mr2=90,90,9&0,90,90&mr3=30,30,30,30,30 before spliting the array

Member Avatar for diafol

Check for the existence of each $_GET parameter and validate each one. I don't see why you have to mess around or be concerned with the position of '&'.

If you must have all 3 params:

if(isset($_GET['mr']) && isset($_GET['mr2']) && isset($_GET['mr3'])) ...

Once that test is passed, validate each, e.g. with regex. If you get a fail anywhere along the way, report it. Can't see the need to programmatically fix. If your program is spitting out bad urls, then you need to address it, not fix it. If users are entering bad params, tell 'em to stop it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.