Bruce Bruce - 1 year ago 54
Javascript Question

match user input url to url in php variable

There is a variable

$string = '';

There is an input

<input type="text" class="theurl" />

I need to verify the first part of the data the user adds to the input matches the first part of the string. Meaning the user data should begin with:

But not verify whatever comes after that /, meaning the user can change the


part of things. I am very much still learning php and have come a long way, but this is WAY over my head.

Note I do not want to prefill the data for the user and do not know the variable link ahead of time. I just want to match and verify. Perhaps a mix of jquery/js and php?

I don't even know where to begin. Help? Perhaps example code specific to my issue?

Update / Final

So far here is what i have figured out

$re = "/http:\\/\\/([^\\/\\r\\n]+)/";
$string = $baffiliate;
$newstring = preg_match($re, $string, $matches);
foreach($matches as $key=>$value)
$value = $value;
if(strpos($_POST['affiliate'], $value) === false) {
echo 'error';
}else{ something

I opted to use this solution as it didn't require an extra count of thee variable during test :)

Answer Source

You can use STRPOS.

 $string = '';
 if(strpos($string, '') >= 0) {
    echo 'valid';   
 } else {
    echo 'invalid'; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download