Jump to content

php Regex Question...


phpSensei

Recommended Posts

I am terrible at understanding, and writing regular expressions, and using preg_match(); .

 

I need some code that can detect"<TAG> string </END TAG>", and replaces the <TAG> and </Tag> with something of my own...

 

basically, this is for a ["b"][/"b"], and ["url"=""][/url] code I need for my forum....

Link to comment
https://forums.phpfreaks.com/topic/67252-php-regex-question/
Share on other sites

Here's a quick example. You can find more by searching the forums for "bbcode".

 

<pre>
<?php
$string = '<TAG>stuff</TAG>';
echo preg_replace('#<([^>]+)>(.*?)</\1>#', '[b]$2[/b]', $string);
?>
</pre>

 

lol thanks, but i dont understand a word of it. @$#@$#@$#@%$#%$^%$$&%D>>>>

Link to comment
https://forums.phpfreaks.com/topic/67252-php-regex-question/#findComment-337794
Share on other sites

Even after reading through the manual?

 

Here's an explanation from Perl's YAPE::Regex::Explain:

NODE                    EXPLANATION

----------------------------------------------------------------------

  <                        '<'

----------------------------------------------------------------------

  (                        group and capture to \1:

----------------------------------------------------------------------

    [^>]+                    any character except: '>' (1 or more

                            times (matching the most amount

                            possible))

----------------------------------------------------------------------

  )                        end of \1

----------------------------------------------------------------------

  >                        '>'

----------------------------------------------------------------------

  (                        group and capture to \2:

----------------------------------------------------------------------

    .*?                      any character except \n (0 or more times

                            (matching the least amount possible))

----------------------------------------------------------------------

  )                        end of \2

----------------------------------------------------------------------

  </                      '</'

----------------------------------------------------------------------

  \1                      what was matched by capture \1

----------------------------------------------------------------------

  >                        '>'

----------------------------------------------------------------------

Link to comment
https://forums.phpfreaks.com/topic/67252-php-regex-question/#findComment-337817
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.