Jump to content

Read Specific String inside HTML file


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

you can put the sentence in a variable and explode it to get the array keys values. then put the corresponding array key (that has a numeric value) in a variable.

 

<html>
<head></head>
<body>
<?php

$optionstatement="<p>PHP freaks!!! Awesome site!!! blah blah.. Here is your first number: 1 and your second number: 2</p>";
echo "$optionstatement\n";
$dice = explode(" ", $optionstatement);
$value1 = $dice[11];
$value2 = $dice[16];

?>
</body>
</html>

Link to comment
Share on other sites

You may be able to do it by wrapping the desired content in a specific span or div tag with an id or class and use regex to find that particular piece.

 

I am not sure how good javascript is at passing data into a php file as it has been a long time since I tried, but you may be able to get the innerHTML of the div or span and drop the results into a PHP var.... but again I am not sure if that would work at all since JS is client and PHP is server side.

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.