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
https://forums.phpfreaks.com/topic/84688-read-specific-string-inside-html-file/
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>

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.

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.