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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:34:12+00:00 2026-06-12T15:34:12+00:00

I have a String variable containing text file (such as .html) using fopen() and

  • 0

I have a String variable containing text file (such as .html) using fopen()
and next im going to strip_tags() so that i can use that untaged text for an article preview, but before that, I need to get h1 nodeValue, and as well count characters of it, so i can replace the zero in the code below with that value, and end with 150+ that value.

$f = fopen($filepath,"r");
$WholeFile = fread($f, filesize($filepath));
fclose($f);
$StrippedFile=strip_tags($WholeFile);
$TextExtract = mb_substr("$StrippedFile", 0,150);

What is the best way for me to go?
Is a parser the answer? Since this is only situation [so far] I will be extracting values from html tags

  • 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-12T15:34:13+00:00Added an answer on June 12, 2026 at 3:34 pm

    If you are certain of the content of the file you are processing, and know that the title is in H1, you could potentially slice the string you are getting at the
    </h1> location (using strstr() for example although there are a plethora of ways to do that), into two strings.

    You can then strip tags on the first one to get the title and strip tags on the second one to get the content. This is assuming your file ONLY has a single h1 containing the title, before the dom element that contains the content of the article.

    Keep in mind this is not the best way to parse a wide range of articles online, for a more general solution I’d look into a dedicated parser class.

    Here is a code sample :

    Code sample

    $f = fopen($filepath,"r");
    $WholeFile = fread($f, filesize($filepath));
    fclose($f);
    // Modified part
    $content = strip_tags(strstr($WholeFile, '</h1>'));
    $title = strip_tags(strstr($WholeFile, '</h1>', true)); // Valid with PHP 5.3.0 only I think
    $TextExtract = mb_substr($content, 0,150);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable containing a string. The string can come in several ways:
I have javascript string variable with var sttr=We prefer questions that can be answered
If I have a variable containing a string, is there a way that I
I have a variable string text containing lets say ABCDEFGHIJKL. I want to trim
I have a function that reads a text file containing two lines, it reads
I have a variable containing html string. This string has this particular code <a
I have a string variable containing time in hh:mm:ss format . How to convert
I have a string containing the variable name. I want to get the value
I have a string variable containing a function. the function looks like this: def
I have a variable 'start' that initializes with a value 0. How can i

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.