No announcement yet.

A question about sort of vbcodes again

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    Simply, you don't

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

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


    • #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!


      • #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.


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


          • #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?


            • #7
              $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

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


              • #8
                ok thanks man


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