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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:52:30+00:00 2026-06-10T23:52:30+00:00

Earlier today I asked a question about having regex solution for replacing hrefs of

  • 0

Earlier today I asked a question about having regex solution for replacing hrefs of all links in html with return fo some function..

Then I deleted it because it seemed I could work around with it using DomDocument, but It turns out, I can’t…

See my html has got lots of wrong html syntex, html5 code etc, etc..So neither loadHTML, loadXML is working..

Please if someone can provide solution with regex to look-for href’s and replace using calling a function on all..I’ve tried preg_replace, and preg_replace_callback, but I can’t understand the $1, $2..whole concept..
I’ve searched all similar questions, but they all have answers of DomDocumenet, which I can’t use..

Old similar questions:
Grabbing the href attribute of an A element

Find all hrefs in page and replace with link maintaining previous link – PHP

but I need regex solution

  • 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-10T23:52:31+00:00Added an answer on June 10, 2026 at 11:52 pm

    I created one..the main problem usually people afraid are having other attributes, before href, after href, spaces, having wrong url specification, href url in single or double quotes, etc..The big advantage is that I learned how to use them..

    $callback = function ($match) use($params){
            $data = MyClass::updateUrl($match[2], $params);
            $return_data = 'href='.$match[1].$data.$match[1];
            return $return_data;
        };
        $reg = "#href\s*=\s*(\"|')?([^\"'>]+)(\"|')#i";
        return preg_replace_callback($reg, $callback, $html);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a question earlier today about singletons, and I'm having some difficulties understanding
Earlier today, I asked a question about the way Python handles certain kinds of
Earlier today I encountered a limitation of F# quotations, and asked a question about
Some of the responses to a question I asked today earlier today have caused
Earlier today I asked a question about configuring log4net from code and got an
Earlier today I asked this question . After spending some time investigating this issue,
Earlier today I asked a question about environ , and one of the more
Earlier today I asked a question about passing dictionary values to a function. While
I asked a question earlier today ( Methods of Managing Source Code ) as
I asked a question earlier today here . However, what I neglected to check

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.