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

  • Home
  • SEARCH
  • 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 609247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:32:45+00:00 2026-05-13T17:32:45+00:00

I store the content of a website in a string $html . I want

  • 0

I store the content of a website in a string $html.

I want to count all html links that link to a file in the .otf format, add a list of these links to the end of $html and remove the original links.

An example:

<?php
$html_input = '
<p>
    Lorem <a href="font-1.otf">ipsum</a> dolor sit amet, 
    consectetur <a href="http://www.cnn.com">adipiscing</a> elit.
    Quisque <a href="font-2.otf">ultricies</a> placerat massa 
    vel dictum.
</p>'

// some magic here    

$html_output = '
<p>
    Lorem ipsum dolor sit amet, 
    consectetur <a href="http://www.cnn.com">adipiscing</a> elit.
    Quisque ultricies placerat massa 
    vel dictum.
</p>
<p>.otf-links: 2</p>
<ul>
    <li><a href="font-1.otf">ipsum</a></li>
    <li><a href="font-2.otf">ultricies</a></li>
</ul>'
?>        

How do I do that? Should I use regular expressions, or is there another way?

  • 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-13T17:32:45+00:00Added an answer on May 13, 2026 at 5:32 pm
    require_once("simple_html_dom.php");
    
    $doc = new simple_html_dom();
    $doc->load($input_html);
    
    $fonts = array();
    $links = $doc->find("a");
    
    foreach ( $links as $l ) {
        if ( substr($l->href, -4) == ".otf" ) {
            $fonts[]      = $l->outertext;
            $l->outertext = $l->innertext;
        }
    }
    
    $output = $doc->save() . "\n<p>.otf-links: " . count($fonts) ."</p>\n" .
        "<ul>\n\t<li>" . implode("</li>\n\t<li>", $fonts) . "</li>\n</ul>";
    

    Documenation for Simple HTML DOM http://simplehtmldom.sourceforge.net/

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

Sidebar

Related Questions

For my website I want to store the general format of the site in
The application that I'm designing will retrieve and store content from a variety of
I store some time values in sqlite in %H:%M string format (for example 15:43),
My company is in education industry and we use XML to store course content.
I need to store an array in a custom content type in MOSS. This
If I store the contents of an xml file (name -> value) in a
I'm searching for a string in a website and checking to see if the
I have a website in which I update the content approximately once monthly. When
I am developing a website that has some sort of realtime update. Now the
My client has a website which is currently semi-static html pages: it contains dynamic

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.