Francky683 Posted August 3, 2006 Share Posted August 3, 2006 Hey buds,I'm stuck on a problem with a preg_replace line, here it is : [code=php:0]<? $text = "[flag]usa[/flag]"; $flagSize = "18-12"; $flagArray['usa'] = 'United States'; $outputText = preg_replace("/\[flag\]([a-z]{3})\[\/flag\]/", "<img src=\"images/flags/$flagSize/$1.gif\" class=\"flag\" alt=\"$flagArray[$1]\">", $text); echo $outputText;?>[/code]If somehow doesn't accept the array within the function, anyone?Best regards,Francis B. Link to comment https://forums.phpfreaks.com/topic/16465-help-with-array-within-preg_replace/ Share on other sites More sharing options...
wildteen88 Posted August 3, 2006 Share Posted August 3, 2006 Try:[code=php:0]<?php$text = "[flag]usa[/flag]";$flagSize = "18-12";$flagArray['usa'] = 'United States';function getFlag($flag){ global $flagSize, $flagArray; $flag = '<img src="images/flags/' . $flagSize . '/' . $flag . '.gif" class="flag" alt="' . $flagArray[$flag] . '">'; return $flag;}$outputText = preg_replace("/\[flag\]([a-z]{3})\[\/flag\]/e", "getFlag(\"$1\")", $text);echo $outputText;?>[/code] Link to comment https://forums.phpfreaks.com/topic/16465-help-with-array-within-preg_replace/#findComment-68665 Share on other sites More sharing options...
Francky683 Posted August 3, 2006 Author Share Posted August 3, 2006 Know what? I love you. Definately works.Luv ya bud.Francis B. <3 Link to comment https://forums.phpfreaks.com/topic/16465-help-with-array-within-preg_replace/#findComment-68671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.