Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Question with regex_replace

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
popo_ny
Smarty Rookie


Joined: 04 May 2009
Posts: 6

PostPosted: Mon May 04, 2009 10:37 am    Post subject: Question with regex_replace Reply with quote

Hello to all,

I am new in smarty and go slightly lost. I have a problem at the moment of trying parse the content of the variable of text and apply a style to him determined on having found the etiquette [quote=nameofuser] where nameofuser is the name of the username in the text.

I have tried to realize it this way

Code:
$text_to_replace|regex_replace:"/\[quote\=(.*?)\](.*?)\[\/b\]/is":"<div class='classquote'>"


But it does not do anything.

Thank's and regards!

PD.: Excuse me but my english is very poor
Back to top
View user's profile Send private message
alokin
Smarty Regular


Joined: 14 Apr 2009
Posts: 96
Location: Belgrade, Serbia

PostPosted: Mon May 04, 2009 11:17 am    Post subject: Re: Question with regex_replace Reply with quote

popo_ny wrote:
PD.: Excuse me but my english is very poor

Yeah, you're right, I haven't understood your first paragraph at all... Smile

I don't understand what are you trying to replace with that regex. That part with "*?" is just not right. If you just want to replace [quote=nameofuser] pattern with <div class = "classquote">, then this should do the job:
Code:

$text_to_replace|regex_replace:'/\[quote\=.+\]/is':'<div class="classquote">'

You didn't mentioned that [/b] part in your first paragraph... Explain more precisely what're you trying to accomplish...
_________________
www.nikolaposa.in.rs
Back to top
View user's profile Send private message
popo_ny
Smarty Rookie


Joined: 04 May 2009
Posts: 6

PostPosted: Mon May 04, 2009 12:50 pm    Post subject: Re: Question with regex_replace Reply with quote

alokin wrote:

I don't understand what are you trying to replace with that regex. That part with "*?" is just not right. If you just want to replace [quote=nameofuser] pattern with <div class = "classquote">, then this should do the job:
Code:

$text_to_replace|regex_replace:'/\[quote\=.+\]/is':'<div class="classquote">'

You didn't mentioned that [/b] part in your first paragraph... Explain more precisely what're you trying to accomplish...


Thank's for response I suppose slope a bit understanding me in occasions... Smile

I'm trying to change the bbcode of a one field of text to the html. I have tried your code and it works well, but when it finds more than one coincidence it eliminates some fragments of the text.

Since I can specify that there can be more than one coincidence at the moment of replacing the BBCODE by his html code with regex_replace?

Thank you very much for your help

PD: Edit...

Quote:
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times


I understand that ". * " it would be the correct one in PHP ... from the tpl of smarty not if it is the appropriate one.

I have tried it but it does not work correctly, it eliminates some fragments of the text


PD2:
I test it and I detect It eliminates the text of the interior of the etiquette bbcode [quote]
Back to top
View user's profile Send private message
popo_ny
Smarty Rookie


Joined: 04 May 2009
Posts: 6

PostPosted: Mon May 04, 2009 1:27 pm    Post subject: Reply with quote

An example of text bbcode to convert in html

Code:

[quote=user1]
Some text...

[quote=user2]
Text...
[quote=user3]
Some text...
[/quote]
[/quote]


alokin, with your code the text that this inside the [quote] is eliminated and not parse all the blocks of [quotes]

Thank's again
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon May 04, 2009 1:35 pm    Post subject: Reply with quote

This would be much better handled with a plugin, not regex_replace.
Back to top
View user's profile Send private message Visit poster's website
popo_ny
Smarty Rookie


Joined: 04 May 2009
Posts: 6

PostPosted: Mon May 04, 2009 1:47 pm    Post subject: Reply with quote

Hello mohrt

I am working with a script of test(proof) and the code of the part of php this one protected by means of ioncube.

A friend have asked me, as personal favor, to look of settling certain problems in the formatting of some paragraphs in order to take a decision and to buy or not the script.

The real problem is that has turned already into slightly personal Crying or Very sad Wink
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon May 04, 2009 1:58 pm    Post subject: Reply with quote

The smarty libarary is encoded? Hmm. it shouldn't be. you should be able to add plugins to smarty even if the rest of the code is encoded. If Smarty is encoded, alert them of their violation of the LGPL license Smarty is under.
Back to top
View user's profile Send private message Visit poster's website
alokin
Smarty Regular


Joined: 14 Apr 2009
Posts: 96
Location: Belgrade, Serbia

PostPosted: Mon May 04, 2009 2:00 pm    Post subject: Reply with quote

Ok, so you need to convert this:
Code:
[quote=user3]
Some text...
[/quote]

... into this:
Code:
<div class = "quote">
<p class = "quote_title">user3</p>
Some text...
</div>

This regex should do the work:
Code:
preg_replace('/\[quote=(.+)\](.+)/[\/quote\]/Uis', '<div\sclass=\"quote\"><p\sclass=\"quote_title\">\1<\/p>\2<\/div>', $text);

Pay attention on that "U" modifier, at the and of regex pattern. Now you just need to create a plugin that will use that regex.
_________________
www.nikolaposa.in.rs
Back to top
View user's profile Send private message
popo_ny
Smarty Rookie


Joined: 04 May 2009
Posts: 6

PostPosted: Mon May 04, 2009 2:30 pm    Post subject: Reply with quote

mohrt wrote:
The smarty libarary is encoded? Hmm. it shouldn't be. you should be able to add plugins to smarty even if the rest of the code is encoded. If Smarty is encoded, alert them of their violation of the LGPL license Smarty is under.


No! Smile Some php files of the script are encoded.

alokin, mohrt... Thank's a lot for all!

I try to create a plugin
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon May 04, 2009 2:32 pm    Post subject: Reply with quote

The wiki m ay be of use too.

http://smarty.incutio.com/?page=BBCodePlugin
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP