Joan Silverstone
Joan Silverstone

Reputation: 385

using php preg_match to find a single number

I am trying to find a single ID from a HTML page i am pulling with cURL. The id is in a url query string that finishes like so:

start_working&locID=12008'

Since that's the only place where that piece of text appears in the html i am guessing thats the pattern we are looking for.

All i need is that locID number.

Like:

preg_match("start_working&locID=".$what_i_want."'")

I am really bad with regex and preg match

Upvotes: 1

Views: 882

Answers (2)

lorenzo-s
lorenzo-s

Reputation: 17010

$match = array;
preg_match('/start_working&locID=([0-9]+)\'/', $yourHtmlToParse, $match);

Then you can use $match[1] for your result.

Upvotes: 2

mario
mario

Reputation: 145482

(\d+) is the pattern to get you numbers. You also need / delimiters / in your regex.

You might also want to investigate parse_str() though, after extracting the full URL.

Upvotes: 1

Related Questions