سؤال

I have this kind of retrieved record from a database where I want to decode formatting values and replace it with appropriate html tag so that it will work fine on display:

[size=150:3a9xfsiy][color=#000080:3a9xfsiy]hello world[/color:3a9xfsiy][/size:3a9xfsiy]

This record was created by phpBB and I am using it to display on other part of the website outside phpBB's control..

What ive tried is to use PREG_REPLACE but question is, is there any way to read different formatted tags as one in regex? example:

[size=150:3a9xfsiy] and [/size:3a9xfsiy] must be searched in a single preg_replace
هل كانت مفيدة؟

المحلول

<?
    $ret = 'I gave my Word to you Word.';
    $pattern = '/\bWord\b/i';
    $ret = preg_replace($pattern,"Heart",$ret);
    var_dump($ret);
?>

string(29) "I gave my Heart to you Heart."

Or if this is what suits you

You could just use str_replace:

$str = str_replace(array('<tag>', '</tag>'), array('<newtag>', '</newtag>', $str);

نصائح أخرى

Phpbb provides a function for this. Generate_text_for_display. When you retrieve it from db, include phpbb functions and apply this function.

Also you can use this class.

Read more about parsing text.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top