basically what it says in the source of the file is:
Code: Select all
<TD><b>Price</b>: $0.50 So How do I have it parse that number?
Thanks.
Moderator: General Moderators
Code: Select all
<TD><b>Price</b>: $0.50 Code: Select all
$price = array();
preg_match('/\$(\d+)?\.\d+/', "<TD><b>Price</b>: $0.50 ", $price);Its actually only like one line of code to get just the $0.50. I just need to see the rest of the page to give you the code for it. You have to check for specific things in the page, cut to that point, then find first occurrence of $, and substring from there to first & symbol. Post the page where you want to do this from if you want the code.WebbieDave wrote:Then chop the $Code: Select all
$price = array(); preg_match('/\$(\d+)?\.\d+/', "<TD><b>Price</b>: $0.50 ", $price);
Anything more and you'll probably need an HTML parser which you can easily google for.
Code: Select all
preg_match('/Price.{0,10}?:.{0,20}?(\d+(\.\d+)?)/i', "<TD><b>Price</b>: $0.50 ", $groups);
$price = floatval($groups[1]);Code: Select all
<form action="welcome.php" method="post">
<input type="radio" name="faction" value="Light" checked="checked" />
<img src="Light.gif" width="50" height="50" /> Light
<br />
<input type="radio" name="faction" value="Machines" />
<img src="Machines.gif" width="50" height="50" /> Machines
<br />
<input type="radio" name="faction" value="Magic" checked="checked" />
<img src="Magic.gif" width="50" height="50" /> Magic
<br />
<input type="radio" name="faction" value="Nature" />
<img src="Nature.gif" width="50" height="50" /> Nature
<br />
<input type="radio" name="faction" value="Neutral" />
<img src="Neutral.gif" width="50" height="50" /> Neutral
<br />
<input type="radio" name="faction" value="War" checked="checked" />
<img src="War.gif" width="50" height="50" /> War
<br />
<input type="submit" />
</form>Code: Select all
You selected the <?php echo $_POST["faction"];?> faction.
<img src=<?php echo $_POST["faction"];?>.gif width="50" height="50" />
<META HTTP-EQUIV="Refresh"
CONTENT="2; URL=<?php echo $_POST["faction"]; ?>.php">Code: Select all
<?php
$your_variable = "0";
$your_file = "Light Units.txt";
$read_your_file = @fopen($your_file, "r") or die ("Couldn't Access $your_file");
$contents_your_file = fread($read_your_file, filesize($your_file));
$your_array = explode("\n",$contents_your_file);
fclose($read_your_file);
$num_elmnts_array = count($your_array) ;
$your_menu = "<select name=\"Unit\">";
for($counter = 0; $counter < $num_elmnts_array; ){
$your_menu .= "<option value=$your_array[$counter]>$your_array[$counter]
</option>";
$counter++;
$your_variable++;
}
$your_menu .= "</select>";
?>
<form action="results.php" method="post">
<p><b>Pick a Unit</b><br>
<br>
<?php echo "$your_menu";?>
<br>
<br>
<input type="submit" />
</form>Code: Select all
<?php $url = "http://www.sagatraders.com/store/CS_";
echo $url;
echo $_POST["Unit"];
echo ".html";
?>
<BR>You searched for <?php echo $_POST["Unit"]; ?>.
Code: Select all
<html>
<head>
<title>
<?php echo $_POST["Unit"]; ?>
<body>
<?php $URL = "http://www.sagatraders.com/store/CS_" . $_POST["Unit"] . ".html";
?>
<BR>You searched for <?php echo $_POST["Unit"]; ?>.
<BR><BR>Getting price from <?php echo $URL ?>
</body>
</html>Code: Select all
<html>
<head>
<title>
<?php echo $_POST["Unit"]; ?>
<body>
<?php $URL = "http://www.sagatraders.com/store/CS_" . $_POST["Unit"] . ".html";
$lines = file($URL);
$line179 = $lines[179];
preg_match('/Price.{0,10}?:.{0,20}?(\d+(\.\d+)?)/i', $line179, $groups);
$price = floatval($groups[1]);
?>
<BR>You searched for <?php echo $_POST["Unit"]; ?>.
<BR><BR>Getting price from <?php echo $URL; ?>
<BR><BR><?php echo $_POST["Unit"]; ?> costs <?php echo $price ?>
</body>
</html>problem is somewhere in there it doesn't grab the right thing, and the price comes out as "0" Any Ideas?You searched for Juggernaut.
Getting price from http://www.sagatraders.com/store/CS_Juggernaut.html
Juggernaut costs 0
Code: Select all
<?php $URL = "http://www.sagatraders.com/store/CS_" . $_POST["Unit"] . ".html";
$page_source = file_get_contents($URL);
preg_match('/Price.{0,10}?:.{0,20}?(\d+(\.\d+)?)/i', $page_source, $groups);
$price = floatval($groups[1]);
?>