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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.