Jump to content

[SOLVED] preg_match help


adv

Recommended Posts

<?php
$nume="";
$str="<span>welcome </span><span class=blu12 style=font-weight: bold;>name lastname</span>";
preg_match('/<span>(.*?)<\/span><span>(.*?)<\/span>/', $str, $al);
if(count($al) != 0) { 
	$nume = $al[1];
}

echo $nume;
?>

 

dunno how to quite put this

as u see from my code ..  i want to echo  welcome name lastname ; but dunno how preg_match quite works .

from the first span to the last span to echo it

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

are you trying to extract the data from the string ? if so this should work

 

<?php
$nume="";
$str="<span>welcome </span><span class=blu12 style=font-weight: bold;>name lastname</span>";
preg_match('/<span[^>]+(.*?)<\/span>/', $str, $al);
if(count($al) != 0) { 
	$nume = $al[0];
}

echo $nume;
?>

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.