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 7984593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:19:32+00:00 2026-06-04T11:19:32+00:00

I would like to replace relative URLs to absolute URLs in a textarea. So

  • 0

I would like to replace relative URLs to absolute URLs in a textarea. So something like this:

/somefolder/somefile 

Is replaced to:

http://www.mysite123.com/somefolder/somefile

I have this replace function to do the job:

$replaceStrs = array('href=/', "href='/", 'href="/');
$datdescription = str_ireplace($replaceStrs, 'href="http://www.' . $domain . "/", $datdescription);
  1. The problem is that it needs a / in the start of the value and therefore a URL like href=somefolder/somefile would not be replaced.
  2. I also would like it to work if there are spaces before or / and after the = in the href part.

Point 1 is most important. Can you help to improve this?

I have seen PHP examples that replaces relative URLs to absolute URLs like this one.

But the requirement is that the relative URL is known / found but in my case I have not managed this part (I am working with replacing all URLs in a textarea).

  • 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-06-04T11:19:33+00:00Added an answer on June 4, 2026 at 11:19 am

    PHP:

    function expand_links($link) {
        return('href="http://example.com/'.trim($link, '\'"/\\').'"');
    }
    $textarea = preg_replace('/href\s*=\s*(?<href>"[^\\"]*"|\'[^\\\']*\')/e', 'expand_links("$1")', $textarea);
    

    I also changed the regex to work with either double quotes or apostrophes.

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

Sidebar

Related Questions

I would like to convert an absolute path into a relative path. This is
I would like to replace blank spaces/white spaces in a string with commas. STR1=This
I have this sample string where I would like to replace the star with
would like to replace all occurence of, double quote included http://somebunchofchar to link I
I would like to replace PKMvrMedsProductIssuesId for something like x=>x.PKMvrMedsProductIssueId or anything that is
I have code like this: <span> <svg height=32 version=1.1 width=32 xmlns=http://www.w3.org/2000/svg style=overflow: hidden; position:
I have a pipe delimited string like this: blah|blah|blah|blah|blah|blah|blah|blah|blah|oldDate|blah|blah| I would like replace the
i would like to replace my node-http-proxy module with nginx proxy_pass module. Is it
I would like to replace only the group in parenthesis in this expression :
I would like to replace drop down list (that has on change event that

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.