[Solar-talk] Solar_Markdown_Plugin & preg_replace

Paul M Jones pmjones at ciaweb.net
Mon Apr 30 07:52:47 PDT 2007


On Apr 30, 2007, at 9:39 AM, Rodrigo Moraes wrote:

> Hey,
> Maybe a regexp expert can give me a help. I have a legacy code which
> parses inline images using the a syntax like the following:
>
> <%image(image_file.jpg|width|height|alt text)%>
>
> Now I would like to use a Solar_Markdown_Plugin to parse it and start
> using only Solar_Markdown for text parsing. I'm almost there. The
> problem is to include < and > in the regexp.
>
> The best I could get was this:
>
>         $text = preg_replace_callback('{
>             (                                   # wrap whole match  
> in $1
>               %image\(
>                 (.*?)                           # href = $2
>               \|
>                 (.*?)                           # width = $3
>               \|
>                 (.*?)                           # height = $4
>               \|
>                 (.*?)                           # title = $5
>               \)%
>             )
>             }xs',
>             array($this, '_parseInline'),
>             $text
>         );
>
> Then for <%image(file.jpg|307|783|some text)%>, I get:
> $1 = %image(file.jpg|307|783|some text)%
> $2 = file.jpg
> $3 = 307
> $4 = 783
> $5 = some text
>
> So, I couldn't set up a regexp to also include < and > in the
> replacement. :-| Can anybody help?

Maybe try these?  (Note the \< and \> at the beginning and end.)

     \<\%image\(    # for the opening tag

     \)\%\>         # for the closing tag

Hope this helps.


--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.  <http://solarphp.com>

Join the Solar community wiki!  <http://solarphp.org>

Savant: The simple, elegant, and powerful solution for
templates in PHP.  <http://phpsavant.com>




More information about the solar-talk mailing list