Jump to content

[SOLVED] Finding a certain string in a bunch of text


Asheeown

Recommended Posts

I'm using a site to find a value I need.  When I pull the HTML for the site I put it into the variable $Info.  I need to find "Requires level xx" in all that text.  There are no unique HTML tags around it, I need the number after it, 'xx'.  Almost always it's a two digit number, could possibly be a one.  Anyone know how I could do this?

$strpos = strpos('Requires level', $info); // I might have the args in the wrong order, but that's the idea

$strpos = $strpos + strlen('Requires level') + 1; // +1 for the space after it

$level = substr($info, $strpos, 2);

 

Hope that helps...

Floy, yours worked perfectly, sorry guys, didn't get to try yours out before I did Floydian's.

 

You did have the args mixed on the first function, here is my working script:

$strpos = strpos($Info, 'Requires level');
$strpos = $strpos + strlen('Requires level') + 1;
$level = substr($Info, $strpos, 2);

 

Fort this was a regex issue finding words from a web page.

 

i differ to agree example. ((am i missing some think here?

 

<?php

$Info="hi the i am red arrow Requires level 29 love php";

$strpos = strpos($Info, 'Requires level');
$strpos = $strpos + strlen('Requires level') + 1;
$level = substr($Info, $strpos, 2);


echo $level;
?>

 

result

29

 

<?php
$word="hi the i am red arrow Requires level 29 love php";

if(preg_match_all("/(Requires level)(.?)[0-9]{0,2}/i",$word,$matched)){
   
   echo $matched[0][0];
}

?>

 

result.

 

Requires level 29

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.