Jump to content

[SOLVED] preg match hidden field


waynew

Recommended Posts

Why are you double escaping the forward slash? And are you sure that exactly

 

<input type="hidden" value="..." name="Checkit"/>

 

appears in the haystack?

 

Your sample data says MemberId, so is Checkit right? Also be sure the cases match, or add the pattern modifier i after the last slash in the pattern to make the search case-insensitive.

Hi. Tbh, I'm guessing here. I'm just trying to use code from other examples.

 

Here's what I have:

 

$pattern = '/<[^>]*name="Checkit"[^>]*value="([^"]+)/';
preg_match($pattern,$this->result,$matches);
array_shift($matches);
print_r($matches);

 

It just printed "Array()".

 

Here's what I found in the source ($this->result)

 

<input type=hidden name=Checkit value=35806834>

Ok. I'm getting somewhere:

 

$pattern = '/<[^>]*name=Checkit[^>]*value=([^"]+)/';
preg_match($pattern,$this->result(),$matches);
array_shift($matches);
print_r($matches);

 

It matched ok, but it also took in the code after it. So I got value=8934782348> <img src

 

Etc

Great, was about to suggest that change :)

 

But beware that your pattern also would match something weird like

 

<div weirdname=Checkitvalue=12345

 

If the syntax in your source doesn't change, I would probably go with something simple like

 

~<input type=hidden name=Checkit value=([0-9]+)>~

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.