I'm working on my first script ever but I'm already having problems. On this page:
http://php.belnet.be/manual/nl/function.preg-match.php
Someone says you can do this with this code;
However, this did not seem to work, so I modified something I thought was wrong ($str_lower instead of $str_low)email at albert-martin dot com
23-Oct-2004 11:39
Here is a faster way of extracting a special phrase from a HTML page:
Instead of using preg_match, e.g. like this:
preg_match("/<title>(.*)<\/title>/i", $html_content, $match);
use the following:
<?php
function ExtractString($str, $start, $end) {
$str_low = strtolower($str);
if (strpos($str_low, $start) !== false && strpos($str_lower, $end) !== false) {
$pos1 = strpos($str_low, $start) + strlen($start);
$pos2 = strpos($str_low, $end) - $pos1;
return substr($str, $pos1, $pos2);
}
}
$match = ExtractString($html_content, "<title>", "</title>");
?>
Making my own code:
Code: Select all
<?
$input = "<ElTank> Silver Nariyid Boots, (6) craft (Silver), AL 350 (6Tinks) : Major Coordination, Impenetrability VI, Minor Focus, Bludgeon Bane VI. Dif 286, [1.3/1.0/1.0/1.1/0.4/0.6/0.4], Value 6,161, 400BU";
function ExtractString($str, $start, $end) {
$str_low = strtolower($str);
if (strpos($str_low, $start) !== false && strpos($str_low, $end) !== false) {
$pos1 = strpos($str_low, $start) + strlen($start);
$pos2 = strpos($str_low, $end) - $pos1;
return substr($str, $pos1, $pos2);
}
}
$name = ExtractString($input, "<ElTank>", ",");
echo $name;
?>The script is small but rather complicated (to a beginner), so I thought I'd ask here