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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:14:07+00:00 2026-06-15T09:14:07+00:00

i am trying to get some preg match done . i have basically come

  • 0

i am trying to get some preg match done .

i have basically come up with this

preg_match_all('<a href="(.*?)">', $page, $result);

but the output of this is

Array
(
    [0] => Array
     (
        [0] => a href="/stuff"
        [1] => a href="/stuffstuffstuff"

         and much more of this.

i want to remove the a href and the slashes and quotes and keep only the content.
ive tried a lot but those things keep coming back , any help would be appretiated.

Thanks guys

  • 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-15T09:14:10+00:00Added an answer on June 15, 2026 at 9:14 am

    First thing, please do NOT try to parse random html with regex, it is not going to work, it’s going to break, sooner or later. Regex is not tool for parsing html, it CanNOT parse it correctly.
    3 simple examples:

    <a href='stuff'> (different quotes)
    <!-- <a href="stuff">-->
    <a style='something' href="stuff">
    

    theese are going to break your application. There is infinite amount of other examples, which will not work and are gonna break it! Not even Chuck Norris can parse html with regex correctly, NOONE can!

    But I assume you already know that, and this is just small simple limited amount of known html, which isn’t going to be released in public, so lets back to your question:

    preg_match_all expects the regex with delimiting characters and it matches all that stuff you write between them. If you write

    '<a href="(.*?)">' 
    

    as a regex, it treats the ‘<‘ at the begining as a delimiting character, thus not matching it. Write slashes (or any other characters) arround it:

    preg_match_all('/<a href="(.*?)">/', $page, $result);
    

    Now, it’s going to match like:

    [0] => <a href="/stuff">
    

    But you want only the ‘/stuff’.
    $result gives you an array. In $result[0] is all the regex matched, in $result[1] is first () matched, in $result[2] would be second ( ) sub-expression matched, and so on… So, you want to look in $result[1], you should find what you want there.

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

Sidebar

Related Questions

Im trying to get some auto complete to work. I have this URL i
I am trying to get the information out of this array, but for some
Just trying to get some rows out of a database and loop through but
Im trying to get some system information using WMI but the problem is when
Based on the thread With PHP preg_match_all, get value of href , I'm trying
I've been going bananas trying to get some data from Javascript on one page
I have this existing code does not work as I am trying to get
I am trying to get the source for images on some pages but there
Getting super frustrated trying to get this working. Basically this is for a site
I am trying to match some of the Javascript on a Youtube video page.

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.