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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:47:12+00:00 2026-06-05T05:47:12+00:00

I am Expanding/Condensing a Blog post using substrings, where the second substring is within

  • 0

I am Expanding/Condensing a Blog post using substrings, where the second substring is within a div tag that activates when a button is pressed (hence concatenating both substrings)

The code looks like as below:

<?php echo substr($f2, 0, 50);?>
<div id="<?php echo $f4; ?>" class = "hidden">
<?php echo substr($f2, 0, 5000);?></div>

My problem however is if the blog post contains html tags (e.g. <\li>, <\p>) and the initial substring ends before the termination of that set of tags, then obviously it causes major formatting problems.
Is there a way around this using my current method, or am I going to need to use something like an XML stylesheet (in which case please guide me through it)

EDIT:

I have semi-completed my request using DOMDocument.

$second = substr($f2, 50, 5000);
$dom= new DOMDocument();
    $dom->loadHTML($second);      
    $xpath = new DOMXPath($dom);
    $body = $xpath->query('/html/body');
$secondoutput = ($dom->saveXml($body->item(0)));


$first = substr($f2, 0, 50);
$dom= new DOMDocument();
    $dom->loadHTML($first);      
    $xpath = new DOMXPath($dom);
    $body = $xpath->query('/html/body');
$firstoutput = ($dom->saveXml($body->item(0)));

This works except, when the second subtring is called it no longer has the previous formatting as it has been purified.
Is there any way to reattch the previous HTML tag when the second substring is called?

  • 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-05T05:47:14+00:00Added an answer on June 5, 2026 at 5:47 am

    There are diffrent solutions to this problem, but substr is not particularly suitable (as you mentioned).
    You could use Regular Expressions, or a HTML-Parser.

    Go ahead and copy solutions from this question.

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

Sidebar

Related Questions

I'm having an issue with an expanding div tag that is nested within another
I have a bunch of divs that I am expanding/retracting individually using .toggle and
I am expanding/collapsing a div using a click event bind on the div. The
My app is expanding, but the reqs dictate that there should be only one
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I've built a very basic grid of divs by using float: However when expanding
I've been using the LongURL.org API for expanding short URLs. The great thing about
I am expanding forms that are created with Zend_Dojo , for this i have
I am trying to get an expanding div to appear correctly in IE7. What
Considering that the family of iDevices is expanding, I guess this is a problem

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.