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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:18:38+00:00 2026-05-23T09:18:38+00:00

Say I have a WordPress post, and certain words are wrapped in span tags.

  • 0

Say I have a WordPress post, and certain words are wrapped in span tags.

For example:

<p>John went to the <span>bakery</span> today,
and after picking up his favourite muffin
he made his way across to the <span>park</span>
and spent a couple hours on the <span>swings</span>
with his friends.</p>

Is then then a way using PHP to dynamically spit them (the words in the span tags) out as an ordered list in my template file?

Like so:

<h3>What John Did Today</h3>
<ol>
<li>bakery</li>
<li>park</li>
<li>swings</li>
</ol>

If someone could point be in the right direction of how to do something like this, it would be much appreciated. Thank you.

  • 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-23T09:18:39+00:00Added an answer on May 23, 2026 at 9:18 am
    $str = '<p>John went to the <span>bakery</span> today, and after picking up his favourite muffin     he made his way across to the <span>park</span> and spent a couple hours on the <span>swings</span> with his friends.</p>';
    
    $d = new DomDocument;
    $d->loadHTML($str);
    
    $xpath = new DOMXPath($d);
    echo "<h3>What John Did Today</h3>\n";
    echo "<ol>\n";
    foreach ($xpath->query('//span') as $span)
      echo "<li>".$span->nodeValue."</li>\n";
    echo "</ol>\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a post called Hello World in Wordpress and I'm directly viewing
I use the new wordpress plugin, google xml sitemap. Hello, lets say I have
Let's say i have two functions in functions.php in Wordpress. function1(){ // it takes
i have a (php) wordpress site on let's say domain1.com and i bought another
I have found out a way to do this is in WordPress: Say you
Inside phpMyAdmin, I am working with custom meta fields in WordPress. Say I have
I have wordpress site on say: http://xyz.com/category-name/ now I changed the category slug to
Say I have a site mysite.com, which is a wordpress site. I already have
Let's say I have a (fictious) post: 'Google and Tesla join to produce smart
Lets say I have the following Categories in Wordpress: Product Category - Cat A

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.