PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm thinking of building in a feature into a database field - it's basically a content management system - to specify a tag in the field which is where the text gets cut off.
So it's being processed before it hits PHP and I can just do normal FileMaker CDML stuff.
<?php
$newsdisplay="";
$maxlength = "180";
$newstext = <<<EODEFIN
Lorem ipsum dolor sit amet, consectetuer 100$ or $100 adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
<img src="/img/myimg" alt="not found">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
EODEFIN;
$words = explode(" ", $newstext);
foreach ($words as $key => $word) {
if ($key < $maxlength) {
$newsdisplay .= $word." ";
} elseif ($key == $maxlength) {
$newsdisplay .= $word."...";
}
}
echo($newsdisplay);
?>
appears to work. I can only guess that the error is caused by the data from the database. Can you give us the example data ?
By the by... using <<< has the disadvantage that $x would be taken as being the variable $x and insert the variables contents. A potential security risk.
<img src="e;http://www.dealer-world.co.uk/eclub/amdmar05/220305 proshowlogo.gif"e; alt="e;"e; border="e;0"e; align="e;right"e; />CUSTOM CHROME DEALER SHOW, MAINZ GERMANY MARCH 19th - 20th, 2005
A total of 64 top class custom builders from Europe and beyond entered 71 bikes in the AMD ProShow, held on Saturday March 19th and Sunday March 20th, to compete for the coveted accolade of being the official Eu
Do I need an addslashes in there somewhere?
To deal with the src=""
Using the sample code provided earlier (which simply pretents to have replaced your tag with the actual HTML) and your sample data produces no error when I try it.
Example (OK also changed the split method, but also worked with the old method).
<?php
$maxlength = "180";
$newstext = <<<EODEFIN
<img src="http://www.dealer-world.co.uk/eclub/amdmar05/220305 proshowlogo.gif" alt="" border="0" align="right" />CUSTOM CHROME DEALER SHOW, MAINZ GERMANY MARCH 19th - 20th, 2005
A total of 64 top class custom builders from Europe and beyond entered 71 bikes in the AMD ProShow, held on Saturday March 19th and Sunday March 20th, to compete for the coveted accolade of being the official Eu
EODEFIN;
$post_txt="";
$words = explode(" ", $newstext);
if (count($words)>$maxlength) {
$post_txt="...";
$words=array_splice($words,0,$maxlength);
$newsdisplay=implode(" ",$words).$post_txt;
} else {
$newsdisplay=$newstext;
}
echo($newsdisplay);
?>
Last edited by CoderGoblin on Thu Mar 24, 2005 8:14 am, edited 1 time in total.
Just to let you know I've solved the problem without using PHP, I've done it in FileMaker.
I would have liked to be able to manipulate cut the data through PHP though, as it's easier to edit the PHP code than it is to take the filemaker web server offline, edit the field definition, every time I want to change the number of words that it cuts the text at.
I'll change the subject to solved but I'll keep looking at ways to do this.