Jump to content

Search Specific String inside HTML


pickachu

Recommended Posts

Hi everyone, i have tried searching google but i never get my desired result.

 

Here is my problem, I making a program that needs to read a specific content. Example, inside a html file..

 

<html>
<head></head>
<body>
<p>PHP freaks!!! Awesome site!!! blah blah.. Here is your first number: 1 and your second number: 2</p>
</body>
</html>

 

I need to put the value of first number (which is 1) inside a variable, and the second number to aother variable.

 

How do I this? I dont have any idea where to start with this..

Link to comment
https://forums.phpfreaks.com/topic/84692-search-specific-string-inside-html/
Share on other sites

$string = 'hello 1 bye 2';
$pat = '~hello (.) bye (.)~';
preg_match_all($pat, $string, $o);
$num1 = $o[1][0];
$num2 = $o[2][0];

 

To extract certain data out of any other data, this is called "parsing" through the data. Regex is a handy & powerful language that can easily parse through data with symbols that make the engine do different things. There are plenty of other ways to parse through data, like creating code algorithms in php.

 

<a href="http://regexadvice.com/blogs/mash/default.aspx">Asking Regex Questions</a>

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.