Announcement

Collapse
No announcement yet.

A question about sort of vbcodes again

Collapse
X
 
  • 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

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

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

    Comment


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


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


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

          Comment


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


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


              • #8
                ok thanks man

                Comment

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