View previous topic :: View next topic |
Author |
Message |
popo_ny Smarty Rookie
Joined: 04 May 2009 Posts: 6
|
Posted: Mon May 04, 2009 10:37 am Post subject: Question with regex_replace |
|
|
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 |
|
alokin Smarty Regular
Joined: 14 Apr 2009 Posts: 96 Location: Belgrade, Serbia
|
Posted: Mon May 04, 2009 11:17 am Post subject: Re: Question with regex_replace |
|
|
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...
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 |
|
popo_ny Smarty Rookie
Joined: 04 May 2009 Posts: 6
|
Posted: Mon May 04, 2009 12:50 pm Post subject: Re: Question with regex_replace |
|
|
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...
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 |
|
popo_ny Smarty Rookie
Joined: 04 May 2009 Posts: 6
|
Posted: Mon May 04, 2009 1:27 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon May 04, 2009 1:35 pm Post subject: |
|
|
This would be much better handled with a plugin, not regex_replace. |
|
Back to top |
|
popo_ny Smarty Rookie
Joined: 04 May 2009 Posts: 6
|
Posted: Mon May 04, 2009 1:47 pm Post subject: |
|
|
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 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon May 04, 2009 1:58 pm Post subject: |
|
|
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 |
|
alokin Smarty Regular
Joined: 14 Apr 2009 Posts: 96 Location: Belgrade, Serbia
|
Posted: Mon May 04, 2009 2:00 pm Post subject: |
|
|
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 |
|
popo_ny Smarty Rookie
Joined: 04 May 2009 Posts: 6
|
Posted: Mon May 04, 2009 2:30 pm Post subject: |
|
|
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! 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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
|