SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30
  1. #26
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, based on your explanation of how things work, shouldn't this work?
    In an ideal world yeah, but this is the magical world of regular expressions where nothing is quite what it seems

    . means any character unless it's inside a character class (a character class is the square brackets) in which case it means a literal .
    You could do a simple regex, for example:
    PHP Code:
    $foo '<img src="one/two/three/four.png" alt="whatever" />';
    preg_match('~<img src=\"(.[^"]+)?\"~'$foo$matches); 
    ..but you've still then to ignore http:// src's, css files, js etc and then also replace the path part of the match which is where all the complications creep in.

  2. #27
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but is
    PHP Code:
    ~<img src=\"(.[^"]+)?\"~ 
    a good replacement pattern?

    also, the reason i put the '.' between imag and src is just incase someone put an extra space or the alt tag before the src=

    Thanks for your patience, I'm new to all this, each post of yours is making me smarter

    Oh, and what does the '~' mean?

  3. #28
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    ~<img.*src=\"(.[^"]+)?\"~
    Seems to be working fine. I'll try and figure out something for the CSS.

  4. #29
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that's closer.
    The ~'s are just the pattern delimiters, sort of like bookends You can use any character you like, for example, /<img src="(.[^"]+)?"/ but I prefer to use a character that's not going to popup in the pattern itself just to make it easier to read. If you want to test your pattern just do var_dump($matches); and whatever is in $matches[1] (in this case) will be what your pattern matched against.

  5. #30
    SitePoint Enthusiast LobsterMan's Avatar
    Join Date
    Apr 2005
    Location
    Jerusalem, Israel
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again,
    I'm trying to figure out something for the css "url()"
    here's what i have so far
    Code:
    $pattern  = '~url((.[^\)]+)?\)~';
    the problem is that it doesn't support url("") and url('')
    I tried this:
    Code:
    $pattern  = '~(url\()|(url\(\')|(url\(")(.[^\)]+)?\)~';
    but it isn't working. what am i Doing wrong?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •