Expression problem

Discussion in 'PHP' started by dizyn, Aug 12, 2008.

  1. #1
    Hi

    I want to fetch 26 out of this using express. I used following code but failed.

    $data = '<span style="text-transform: capitalize;">cloudy</span> 26<abbr title="Temperature in degrees Celsius">°C</abbr>';	
    $pattern = '/</span> (.*)<abbr title/msU';
    preg_match_all($pattern, $data, $matche1);
    PHP:
    thanks
    dizyn
     
    dizyn, Aug 12, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You have to escape the slash inside the </span>.
     
    nico_swd, Aug 12, 2008 IP
  3. beacon

    beacon Peon

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Need escape /
    This work:

    $data = '<span style="text-transform: capitalize;">cloudy</span> 26<abbr title="Temperature in degrees Celsius">°C</abbr>';	
    $pattern = '/<\/span> (.*)<abbr title/msU';
    preg_match_all($pattern, $data, $matche1);
    print_r($matche1);
    PHP:
     
    beacon, Aug 12, 2008 IP
  4. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #4
    
    $data = '<span style="text-transform: capitalize;">cloudy</span> 26<abbr title="Temperature in degrees Celsius">°C</abbr>';    
    $pattern = '#[\d]+#';
    preg_match_all ( $pattern, $data, $matche1);
    
    echo '<pre>';
    var_dump($matche1);
    echo '</pre>';
    
    PHP:
     
    nabil_kadimi, Aug 12, 2008 IP