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
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

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.