A question about sort of vbcodes again

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MeltX
    New Member
    • Aug 2000
    • 20

    A question about sort of vbcodes again

    how to use str_replace() when you want to create something like this for example: img(url) so it won't replace EVERY ) in the string but only when the img( is used, if ya know what i mean.

    really appreciate some help again.
  • Mike Sullivan
    Former vBulletin Developer
    • Apr 2000
    • 13327
    • 3.6.x

    #2
    Simply, you don't

    Code:
    $string=eregi_replace("img\\(([^\\[]*)\\)","<img src=\"\\1\">",$string);

    [Edited by Ed Sullivan on 08-25-2000 at 06:51 PM]

    Comment

    • MeltX
      New Member
      • Aug 2000
      • 20

      #3
      really really tanks man!! i didn't know the eregi cmd at all, could you please explain the meaning of the strange number os slashes(/) in the line and other things?

      thanks again!

      Comment

      • Mike Sullivan
        Former vBulletin Developer
        • Apr 2000
        • 13327
        • 3.6.x

        #4
        Well, I'm far from a regex master, but...

        First off, a "regex" is short for regular expression. Basically, pattern matching.

        "eregi_replace" is the case insensitive regular expression replacer

        "\\(" is just used to escape the "(", as the character is interpretted. I really don't know why you use 2 backslashes - I just took John's code and manipulated it a little. (Same with \\) )

        "([^\\[]*)" is the regular expression code. It will match any one word I believe. This is assigned to \\1, which is used later.

        Basically, you replace stuff around the regex.

        Comment

        • MeltX
          New Member
          • Aug 2000
          • 20

          #5
          Hey man really thanks, this was third time u helped me out!

          Comment

          • MeltX
            New Member
            • Aug 2000
            • 20

            #6
            Another problem

            now when i do img(url) it works ok, but i don't when i do this for example:

            Please look at this picture: img(url) blabla )

            now it passes the first ) and it does stop when it reach the second ) if ya know what ia mean.

            how can i fix this?

            Comment

            • Mas*Mind
              Senior Member
              • Jun 2000
              • 1444

              #7
              Code:
              $string = eregi_replace("img\(([^\)]*)\)","<img src=\"\\1\">",$string);
              not tested, but I think it would work;

              The double slashes are not necessary as far as I know and the ([^\\[]*) part is only necessery for [bbcode] kind of tags...This part says it has to get every character EXCEPT a [ (The ^ sign accomplishes this)

              There's a very good tutorial about regexes on http://www.phpbuilder.com/columns/dario19990616.php3

              [Edited by Mas*Mind on 08-28-2000 at 04:11 PM]

              Comment

              • MeltX
                New Member
                • Aug 2000
                • 20

                #8
                ok thanks man

                Comment

                widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                Working...