Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6066585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:30:59+00:00 2026-05-23T09:30:59+00:00

I have this regex code: $hike_description = nl2br($hike_description); //$hike_description = str_replace(array(‘\n’,’\r’),”,$hike_description); //Convert all urls

  • 0

I have this regex code:

$hike_description = nl2br($hike_description);
//$hike_description = str_replace(array('\n','\r'),'',$hike_description);

//Convert all urls to links
$hike_description = preg_replace('#([\s|^])(www)#i', '$1http://$2', $hike_description);
$pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^\s]+)#i';
$replacement = '<a href="$1" target="_blank">$1</a>';
$hike_description = preg_replace($pattern, $replacement, $hike_description);

It has worked 100% of the time….until now.

In this page the code didn’t work for the first time. Specifically, it didn’t place the ” at the end of the link so the link kept going down the rest of the page:

http://www.comehike.com/hikes/scheduled_hike.php?hike_id=209

You see how the link from the middle of the page extends all the way to the bottom and is not closed?

Any clue why that might have happened this time and not any other time?

Thanks!

ps – this is the HTML that ends up on the page:

<a href="http://maps.google.com/maps?um=1&ie=UTF-8&q=little+river+canyon+center&fb=1&gl=us&hq=little+river+canyon+center&hnear=0x888a614b2e7272e5%3A0x913a5fafeec714d6%2CCentre%2C+AL&ei=GBsFTtedF8vUgAfex6zNAQ&sa=X&oi=local_group&ct=image&ved=0CAQQtgM<br" target="_blank">http://maps.google.com/maps?um=1&ie=UTF-8&q=little+river+canyon+center&fb=1&gl=us&hq=little+river+canyon+center&hnear=0x888a614b2e7272e5%3A0x913a5fafeec714d6%2CCentre%2C+AL&ei=GBsFTtedF8vUgAfex6zNAQ&sa=X&oi=local_group&ct=image&ved=0CAQQtgM<br</a> />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:31:00+00:00Added an answer on May 23, 2026 at 9:31 am

    Your regular expression expects the URL to include all characters up to the next space character. Immediately following the URL was an html <br /> tag and the next space seen by your regex was the space before the /> in that tag. So it thought the URL also included the <br at the beginning of that tag. When the closing </a> was added, it was placed inside a <br /> tag and therefore was invalidated.

    For a quick fix to this specific problem, try changing your regex to look for the < character as well as a space to be a URL terminator:

    $pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^<\s]+)#i';
                                                             --------^^^----
    

    EDIT I think this is the real source of the problem:

    Another possibility is to call nl2br() after doing the text replacement rather than before. That <br /> tag might have been a newline character beforehand. The newline would have been interpreted as a space by your regex and the regex replacement wouldn’t have choked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code regex, which should transform all kind of diffrent urls into
I have borrowed code from this link PHP regex templating - find all occurrences
I have this regex/javascript code: toReturn = toReturn.replace(/(\[url=)(.+)(\])(.+)(\[\/url\])/g, '<a target=\_blank\ href=\$2>\$4</a>'); But the problem
Thanks to Chetan Sastry I have this Regex code to parse my page for
I have this code Regex.Match(contents, @Security=(?<Security>\D+)).Groups[Security].Value; this makes the following: Security=SSPI;Database=Datab_ob How do I
I have this regex. My problem is the two second lines of the code:
I have this replace regex (it's taken from the phpbb source code). $match =
still struggling with regex :) i have this code: $link = '/\bhttp:\/\/.+\..+[\/\w]?\b/i'; $match =
I have found this Regex extractor code in C#. Can someone tell me how
I have this javascript code but when i send this: asd.JPG the regex fails

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.