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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:47:56+00:00 2026-06-10T04:47:56+00:00

I am trying to take the URLs that are in single HTML paragraphs and

  • 0

I am trying to take the URLs that are in single HTML paragraphs and extract them with PHP’s preg_replace_callback. Right now, WordPress does this with:

preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', 'callback_function', $string );

But that matches a URL on it’s own line — no HTML around it. What I need to do is to match the URL from something like this:

<p>http://youtube.com/</p>

I don’t care about the space before or after the paragraph tag, all I want to do is extract that URL to replace it with more detailed information with preg_replace_callback.

Any help out there?


UPDATE:
Okay, I have a post’s text wit a number of paragraphs like this:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et nunc vel felis vulputate tincidunt. In dapibus tempus sollicitudin. Nullam quis ultricies tortor. Ut malesuada aliquet enim. Aliquam et lobortis urna. Sed commodo malesuada malesuada. Donec cursus nisi nec mauris venenatis pharetra. Curabitur ut leo purus.</p>

<p>http://youtube.com/</p>

<p>Etiam non odio tellus, vel imperdiet nunc. Praesent rutrum sagittis purus, quis pretium eros varius ut. http://google.com/ Ut id orci eu lacus aliquam luctus. Sed dolor quam, suscipit eu dapibus feugiat, lacinia vitae augue.</p>

From that text, all I want to extract is that http://youtube.com/ in the paragraph on its own. I see there is a Google.com link in another paragraph, but I don’t want that. All I want is that link (or links) in their own paragraph alone. It would pass to my callback ‘http://youtube.com/&#8217; as the argument.

  • 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-10T04:47:57+00:00Added an answer on June 10, 2026 at 4:47 am

    You could try this: http://regex101.com/r/rN4vB3

    /<p>\s*(https?:\/\/(?:(?!<\/?p>).)+)\s*<\/p>/

    The logic is that we look for a <p> tag that starts with http, and then just get everything else in there until we hit a </p>. The first backreference will hold the URL.

    This might not be an optimal solution, but should do what you asked.

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

Sidebar

Related Questions

I'm trying to use urlretrieve to download files from urls that take the form:
I'm trying to make a VB.NET application that can take some text in (via
I'm trying to write an .htaccess file that will make my URLs more attractive
Trying to take an Array position(toString) and pass that to a new activity, then
So I'm trying to take the variable that increments in a for statement, and
So, I'm trying to create a function which does the following: Receive HTML in
I have a datagridview with 9 columns. I am simply trying take the value
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
Im trying to take a link either when clicked or hover over be able
While trying to take some arguments for C. I found it really difficult to

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.