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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:53:39+00:00 2026-06-18T11:53:39+00:00

I have a string, with a htmlentities encoded HTML code. What I want to

  • 0

I have a string, with a htmlentities encoded HTML code.

What I want to do is find all the paths in the document, between:

href=”XXX”, src=”XXX”.

I do have a regex expression that find all the links starting by http, https, ftp and file, and lest me iterate over it:

"/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i"

Any idea?

  • 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-18T11:53:40+00:00Added an answer on June 18, 2026 at 11:53 am

    Update: Doing it with a regex isn’t reliable. The src=”..” or href=”..” statement can be part of a comment or a javascript statement. To reliable obtain the links I would suggest to use XPath:

    <?php
    
    $html = file_get_contents('http://stackoverflow.com/questions/14782334/regex-expression-to-find-all-paths-in-a-html-string/14782594#14782594');
    $doc = new DOMDocument();
    @$doc->loadHTML($html);
    $selector = new DOMXPath($doc);
    
    $result = $selector->query('//a/@href | //@src');
    foreach($result as $link) {
        echo $link->value, PHP_EOL;
    }
    

    If using a regex I would try to grab the content between the = " of the href or src attribute. Here comes an example how to get the links from this page using a regex:

    <?php
    
    $html = file_get_contents('http://stackoverflow.com/questions/14782334/regex-expression-to-find-all-paths-in-a-html-string');
    
    preg_match_all('/href="(?P<href>.*)"|src="(?P<src>.*)"/U', $html, $m);
                                                            <--- note the U to make the 
                                                                 pattern ungreedy
    var_dump($m['href']);
    var_dump($m['src']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string that displays UTF-8 encoded characters, and I want to convert it
I have a string that is HTML encoded: '''&lt;img class=&quot;size-medium wp-image-113&quot;\ style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;\
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
i have string stored in python variables, and i am outputting a html that
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have a HTML string in ISO-8859-1 encoding. I need to pass this string
I have a string like Welcome to McDonalds®: I'm loving it™ ... I want
I'm having some issues using the following code on user input: htmlentities($string, ENT_COMPAT, 'UTF-8');
I want to run htmlentities() only on the contents within <code> things to strip
I have user input and use htmlentities() to convert all entities. However, there seems

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.