Announcement

Collapse
No announcement yet.

regex and VB code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • regex and VB code

    Can anyone point me in the direction of howto strip all VB code from a string?

    I can strip the tags indvidually but thats no good

    Heres what I have

    PHP Code:
    $newstext ereg_replace("[img]"""$newstext);
    $newstext strip_tags($newstext,"");
    $newstext ereg_replace("^[url]http://[/url]"""$newstext);[/quote
    Unfortunately this leaves VB code in like

    "NEVER"
    or

    Ths s the Font Ths s Bold

    anyone help?


    Thanks in advance

    Dave
    http://forums.cpfc.org/

  • #2
    I'm not 100% sure what you're trying to do.

    Do you just want to remove the [tags] but leave the rest?

    I don't know how it would work in PHP, but regex is a fairly universal language.

    In Perl:
    $text =~ s!\[/{0,1}\w\]!!g;

    Comment


    • #3
      I want to remove the [tags]and everything tagged in here[/tags]

      Essentially I want the straight text from the posts- no html or VB code etc
      http://forums.cpfc.org/

      Comment


      • #4
        For example.. to remove vbcode tags just do..

        $text = preg_replace("/\[img\]/si","", $text);
        $text = preg_replace("/\[\/img\]/si","",$text);

        As for removing html, that is more difficult to do. You can get the more common tags but it will be hard to grab every possible bit of html.
        Last edited by Freddie Bingham; Fri 1 Jun '01, 7:44am.

        Comment


        • #5
          I'm no expert freddie but the [ is a special character so all you have done is replace img rather than the tag [img]


          see below

          http://cpfc.org/forums/addons/active_new.php
          http://forums.cpfc.org/

          Comment


          • #6
            this will strip html and php tags

            http://www.php.net/manual/en/function.strip-tags.php

            This strips HTML and PHP tags from a string.

            Comment


            • #7
              Yes I failed to escape them. You can also modify the regex to just grab everything in between brackets in one swoop and remove it but of course you may have [valid] text that is in brackets that you would want to keep.
              Last edited by Freddie Bingham; Fri 1 Jun '01, 7:48am.

              Comment


              • #8
                Re: this will strip html and php tags

                Originally posted by treszoks
                http://www.php.net/manual/en/function.strip-tags.php

                This strips HTML and PHP tags from a string.
                [img], etc. are not HTML or PHP tags.

                Comment


                • #9
                  Well of course they aren't He mentioned something about no html tags though and I happened to think of that function

                  Comment


                  • #10
                    I'm actually using strip_tags already

                    $newstext = strip_tags($newstext,"");


                    Anyway can anyone post me the code that will strip the VB tags please
                    http://forums.cpfc.org/

                    Comment


                    • #11
                      $text = preg_replace("/\[.*?\]/si","", $text);

                      I'm no php expert but this may work. Basically what freddie posted but to work with everything in brackets.

                      Comment


                      • #12
                        If you want to remove [this]all of this[/and this]

                        $text = preg_replace("/\[.*?\].+?\[/.*?\]/si","", $text);

                        Comment


                        • #13
                          Originally posted by treszoks
                          $text = preg_replace("/\[.*?\]/si","", $text);

                          I'm no php expert but this may work. Basically what freddie posted but to work with everything in brackets.

                          Worked like a charm thanks guys.

                          Can I ask another question?

                          What would be the regex to find every string over 12 characers and replace with a space?

                          Thanks again
                          http://forums.cpfc.org/

                          Comment


                          • #14
                            If by string, you mean a-zA-Z0-9:

                            preg_replace("/[a-zA-Z0-9]{12,}/s", " ", $string);

                            That will literally replace it with a space. If you wanna do a wordwrapping thing, http://www.php.net/manual/en/function.wordwrap.php

                            Comment


                            • #15
                              Man that's cool- love these php functions
                              Last edited by Dave#; Fri 1 Jun '01, 3:24pm.
                              http://forums.cpfc.org/

                              Comment

                              Loading...
                              Working...
                              X