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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:33:42+00:00 2026-05-16T12:33:42+00:00

$string = ‘text <span style=color:#f09;>text</span> <span class=data data-url=http://www.google.com>google.com</span> text <span class=data data-url=http://www.yahoo.com>yahoo.com</span> text.’; What

  • 0
$string = 'text <span style="color:#f09;">text</span>
<span class="data" data-url="http://www.google.com">google.com</span>
text <span class="data" data-url="http://www.yahoo.com">yahoo.com</span> text.';

What I want to do is get the data-url from all spans with the class data. So, it should output:

$string = 'text <span style="color:#f09;">text</span>
http://www.google.com text http://www.yahoo.com text.';

And then I want to remove all the remaining html tags.

$string = strip_tags($string);

Output:

$string = 'text text http://www.google.com text http://www.yahoo.com text.';

Can someone please tell me how this can be done?

  • 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-05-16T12:33:42+00:00Added an answer on May 16, 2026 at 12:33 pm

    If your string contains more than just the HTML snippet you show, you should use DOM with this XPath

    //span/@data-url
    

    Example:

    $dom = new DOMDocument;
    $dom->loadHTML($string);
    $xp = new DOMXPath($dom);
    foreach( $xp->query('//span/@data-url') as $node ) {
        echo $node->nodeValue, PHP_EOL;
    }
    

    The above would output

    http://www.google.com
    http://www.yahoo.com
    

    When you already have the HTML loaded, you can also do

    echo $dom->documentElement->textContent;
    

    which returns the same result as strip_tags($string) in this case:

    text text
    google.com
    text yahoo.com text.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string []URL = {www.facebook.com,www.orkut.com,www.yahoo.com}; Int32 result = URL.Length; SetPolicyURL( URL,result ); this is my
string url = http://google.com/index.html; WebClient client = new WebClient(); Stopwatch sw = new Stopwatch();
String s=asd http://www.blabla.com/bla/foo wert fgh; I want a string: asd <a href='http://www.blabla.com/bla/foo'>http://www.blabla.com/bla/foo</a> wert fgh
string emailfield=txtEmail.Text.ToString(); string url = http://localhost:3076/user/Authenticate-Users.aspx?email=+emailfield; I want to encrypt the querystring and then
String uri = http://maps.google.com/maps?saddr= + src_lat+,+src_lon+&daddr=+des_lat1+,+des_lon1; Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)); intent.setClassName(com.google.android.apps.maps, com.google.android.maps.MapsActivity);
string s = <script type=text/javascript src=/stepcarousel.js></script> How can I get the data inside the
String to pull from : http:\/\/c.ypcdn.com\/2\/c\/rtd?vrid=357c99c36bd7ed631eda2e43fc9e30f8&rid=283d465f-f63b-4b0d-90b0-be6c12ed7617&ptid=943aw4l8qj&ypid=11720135&lid=194823099&tl=6&lsrc=SP&dest=http%3A%2F%2FCleanation.com RegEx I have used before: www\..*?\.\w{2,5} However the
String url = mysite.com/index.php?name=john&id=432 How can I extract the id parameter (432)? it can
String link = http://hosted.ap.org; I want to find whether the given url is already
string in question: '{images:{0:<div style=\\background:red;width:250px;height:250px;display:block;position:absolute;\\></div>}}' I've tried various combinations of single and double quotes.

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.