Jump to content

[SOLVED] preg_match help


adv

Recommended Posts

this is my problem

 

 

<span>Welcome </span><span class="blu10" style="font-weight:bold;">name1 name</span>

 

and with preg_match i`ve tried to show "Welcome name1 name2"

 

if (strstr($result,"<span>Welcome")) {
        preg_match('/<span>(.*?)<\/span><span(.*?)<\/span>/', $result, $al);
        
	if(count($al) != 0) {
                $nume = $al[1];
                $nome = $nume;
                $_SESSION['ben']= $nome;
    }
}

 

 

but it doesnt work ..i`ve echo it and i see only Welcome

 

and another problem

 

<span><br />You have been here for </span> <span>2 days , 30 min ,</span>

 

and i want to exact "You have been here for 2 day , 30 min

i`ve tried with this :

 

if (strstr($result,"<span><br />You have been here for</span>")) {
        preg_match('/<span><br />You have been here for</span><span>(.*?)<\/span>/', $result, $al);
        
	if(count($al) != 0) {
                $check = $al[1];
                $check1 = $check; 
$_SESSION['check'] = $check1;
        }
}

 

thanks in advance :D

Link to comment
https://forums.phpfreaks.com/topic/101918-solved-preg_match-help/
Share on other sites

pff i finally figure it out ..

 

i works without the count() ;

 


$pattern = "/<span>(.*?)<\/span><span(.*?)<\/span>/";
if (strstr($result,"<span>Welcome")) {
        preg_match($pattern, $result, $al);
       $test = $al[0];
}
echo $test;

 

and it works good now .. thanks anyway

Hmm took a look at you code. Wont you get the additional span class data etc also included in your result?

 

if (preg_match('/<span>(.*?)<\/span><span.*?>(.*?)<\/span>/i', '<span>Welcome </span><span class="blu10" style="font-weight:bold;">name1 name</span>', $result))
{
echo $result[1].$result[2];
}

 

Wouldn't this give you the result you requested?

 

You have probably figured out your other problem and one of many ways to get the time is with a pattern like this:

$pattern = '<span>(?=\d)(.*?)<\/span>';

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.