SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Location
    Sweden
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I make preg_match work with newlines/linebreaks in links ?

    Ok, let's say I've got a basic link, and I want preg_match() to match the href="()", title="()" and >()</a> content. I got it all to work except I thought but then I noticed that it would fail if for example the link desc. contains a newline/linebreak.

    Basic link: <a href="www.site.com" title="Title of link">
    Description of link </a>

    In this example the > Description of link </a> contains some spaces and is preceeded by a linebreak. How do I make preg_match() understand it should match everything between > and </a> and ignore the linebreak ?

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using \n or \r, not sure which would be appropriate for you, and * should work.

    That way if there is 0 or more newlines, it will still return true.

    Hope this helps and best of luck!

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by carrier
    Ok, let's say I've got a basic link, and I want preg_match() to match the href="()", title="()" and >()</a> content. I got it all to work except I thought but then I noticed that it would fail if for example the link desc. contains a newline/linebreak.

    Basic link: <a href="www.site.com" title="Title of link">
    Description of link </a>

    In this example the > Description of link </a> contains some spaces and is preceeded by a linebreak. How do I make preg_match() understand it should match everything between > and </a> and ignore the linebreak ?
    Use "s" (dot-match-all) switch.


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
  •