|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
thiagomelo Smarty n00b
Joined: 25 May 2015 Posts: 2
|
Posted: Mon May 25, 2015 9:49 pm Post subject: problems with the regex_replace function |
|
|
Hello, guys.
I'm having a problem getting interpret the way the regex_replace function works.
I have this file that takes the values that you want to transform.
<?php
$search = array (
'/(\[b\])(.*?)(\[\/b\])/',
'/(\[i\])(.*?)(\[\/i\])/',
'/(\[u\])(.*?)(\[\/u\])/',
'/(\[list\])(.*?)(\[\/list\])/',
'/(\[list type=)(.*?)(\])(.*?)(\[\/list\])/',
'/(\[li\])(.*?)(\[\/li\])/',
'/(\[url=)(.*?)(\])(.*?)(\[\/url\])/',
'/(\[url\])(.*?)(\[\/url\])/',
'/(\[img\])(.*?)(\[\/img\])/',
'/(\[hr\])/',
'/(\[quote\])(.*?)(\[\/quote\])/'
);
$replace = array (
'<strong>$2</strong>',
'<em>$2</em>',
'<u>$2</u>',
'<ul>$2</ul>',
'<ul type="$2">$4</ul>',
'<li>$2</li>',
'<a href="$2" target="_blank">$4</a>',
'<a href="$2" target="_blank">$2</a>',
'<div class="news_img"><img src="$2" /></div>',
'<hr />',
'<div class="quote">$2</div>'
);
?>
Before using the smart I just included the file in my code and called the preg_replace($search, $replace, $news);
However in smarty, using as follows:
include("System/bbcodetohtml.php");
$sm->assign('search',$search);
$sm->assign('replace',$replace);
{($row_news->body|nl2br)|regex_replace:"{$search}":"{$replace}"}
Smarty me returns the following error:
Notice: Array to string conversion in C:\xampp\htdocs\L2jWeb\inc\smarty\templates_c\26a8cbb92ce1afec4bdbe5c3b5a9c84aa720210c_0.file.home.tpl.php on line 115
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\L2jWeb\inc\smarty\libs\plugins\modifier.regex_replace.php on line 35
Could someone help me with this error?
I'm sorry for the English, because I'm Brazilian. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue May 26, 2015 5:10 am Post subject: |
|
|
Why you aren't using bbcode modifier? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed May 27, 2015 2:21 am Post subject: |
|
|
True you should use a modifier for this, not regex_replace. However this syntax should get you closer to working:
Code: | {$row_news->body|nl2br|regex_replace:$search:$replace} |
|
|
Back to top |
|
thiagomelo Smarty n00b
Joined: 25 May 2015 Posts: 2
|
Posted: Wed May 27, 2015 2:49 am Post subject: Thx Guys! |
|
|
Perfect, guys.
Actually the plugin worked like I needed, thanks for you tell me about the plugins, as I'm new to the smarty I did not know of the existence of these custom modifiers, now it's just joy, I'm enjoying too much the smarty! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|