To Truncate Text After X Words

I need a script which is called into an existing PHP webpage using this tag:

<? include(“../script/script.php?file=myfile1.txt?temp=template1.php”) ?>


script.php = This script to be created by you.
myfile1.txt = TXT file under a folder path specified under the script.
template1.php = Template (header/footer layout) to be used.

This script will grab all content (which might also include simple HTML codes) from myfile1.txt and display it under the existing PHP webpage.

The script will contain this variable:

max_words = 100;

The script will display only 100 words from myfile1.txt before truncating it off and attach to the end a “… more” link. Clicking on the link will open up a new page (with the template specified) with full content from myfile1.txt.

HTML codes, meaning those words between < and > should not be counted under max_words during truncation.

If the content of myfile1.txt contains ### (three hashes), truncation will be ignored and everything from myfile1.txt will be shown under existing webpage. Meaning, if the administrator does not want any truncation to be carried out for his long text, he can insert ### at the beginning or end of the text.

The ### should be removed from the display (not be printed out).

Leave a Reply

Your email address will not be published. Required fields are marked *