webForumDet fria alternativet

plocka ut

2 svar · 250 visningar · startad av pellesvenne

pellesvenneMedlem sedan jan. 2002227 inlägg
#1

hur gör jag för att plocka ut hejsan!

function test($text) {
$text = preg_replace ("'<b>(*.?)</b>'i", "$1", $text );
return $text;
}

echo test("gg<b>hejsan</b>kkkkk");

jOOOLMedlem sedan sep. 200436 inlägg
#2

först och främst (.*?) ska det vara _inte_ (*.?)
sedan måste du escapepa $1 så här \$1 .
Funktionen bör altså vara så här:

###########

function test($text) {
$text = preg_replace ("'<b>(.*?)</b>'i", "\$1", $text );
return $text;
}

PeeerMedlem sedan mars 20025 907 inlägg
#3
function test($text) {
	preg_match("'<b>(.*?)</b>'is",$text,$text);
	$text = $text[1];
	return $text;
}

echo test("gg<b>hejsan</b>kkkkk");
130 ms totalt · 3 externa anrop · v20260731065814-full.3ab8d573
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
126 ms — hämta tråd, inlägg och bilagor (db)