Sanju Menon Sanju Menon - 1 year ago 98
PHP Question

php truncating field issue

Iam truncating a large field in php. Its all working fine except that iam getting an error on the following line. Iam truncating more than 25 characters with a more hyperlink. When i click the more link, a javascript alert triggers with the actual data.

$length_limit = 25; //limit to this number of characters
$actual_length = strlen($value); //count characters in the $value
$original_text = $value;
$truncated_text = substr($value,0,$length_limit);

if($actual_length <= $length_limit){
$value = $original_text;
} else {
$value = $truncated_text." ... <a onclick='alert(\"'.$original_text.'\")'>more</a>";

Iam getting the error from the last line $value=.... May be some quoatation mark problem. Can someone pls help me with the same.

Answer Source

try this

echo $value = $truncated_text." ... <a onclick=\"alert('".$original_text."')\">more</a>";