Problem in Extracting values

i want to extract value in following html code using php

<input type=“hidden” value=“21” name=“gameNo”>

Assuming that the input tag is part of a form whose method attribute is ‘post’ and that the form has a submit button:

$myExtractedValue = $_POST['gameNo'];

i want to extract it using preg match

I hope someone else can help you because I absolutely don’t dig regex. :frowning:

$html = '<input type="hidden" value="21" name="gameNo">';
$regex = "/value=\\"(\\d+)\\"/";
preg_match($regex, $html, $matches);

$matches[1] will now contain the number 21. Note that this will only work with numbers, if the value of ‘value’ will be more than just numbers then you’d have to change the regex accordingly.

Hiiii,

I strongly advise you to use a real HTML or XML parser for this instead. You cannot reliably parse HTML or XML with regular expressions
Since your HTML code isn’t XML-valid, consider the HTML Agility Pack, which I’ve heard is very good.
Use this regress to extract value,
“<span[^>]>(.?)</span>”
I hope this will help you.

How exactly is that in any way shape or form going to extract a value from the Value attribute of an Input, Harshada?

The DOM parser would be able to find this value for you, which is part of PHP. It would be better if the HTML had an ID tag on the element, but i’m guessing you’re not in control of that.

Standard Disclaimer: Make sure you have permission to scrape whatever data it is you’re trying to.