Forum Moderators: coopster
Heres what I have, short_desc comes out of a mysql db and all works fine
$desc = stripslashes($newArray['short_desc']);function snip()
{
$desc = substr($desc, 0, strpos($desc,'. ', 100));
$desc = $desc."...";
return $desc;
}
}
}
$new_desc = snip();
?><?=$new_desc?>
Warning: strpos(): Offset not contained in string. in /home/public_html/foldername/test.php on line 21 ...
The offset is present its just that calling the chunk of text to the substr() turns up blank, if I remove $desc from the substr and replace it with
$desc = substr("the long chunk of text", 0, strpos("the long chunk of text",'. ', 100));
it all works fine? with $desc all I get is the error and the ...
Any help as always will be much appreciated
You need to declare your $desc as global inside the function or pass it directly into the function:
global $desc;
or
function snip($desc)
$new_desc = snip($desc);
This link may be helpful:
[uk.php.net...]
dc
Cannot redeclare snip($desc)
I understand why but cant figure out what to change, heres my code so far.
$sql="select * from table where widget LIKE '%$widget'";
$result = mysql_query($sql, $dblink) or die("System down");
while ($newArray = mysql_fetch_array($result))
{
$num = $newArray['num'];
$title = $newArray['title'];
$desc = $newArray['widget'];
function snip($desc, $num)
{
$desc = substr($desc, 0, strpos($desc,'. ', 100));
$desc = $desc.' <font size=1>...<BR><BR>( <a href="widget.php?num='.$num.'">Further details on this widget</a> )</font>';
return $desc;
}
$widget_snippet = snip($desc, $num);
print"<font size=\"2\" face=\"Arial, Helvetica, sans-serif\">
<br><b>Widget name:</b> <a href=\"widget.php?num=$num\">$title</a>
<br><br>$widget_snippet</font>";
}
I would prefer to be able to chop the text rather than setup a new field for the snippet text, any ideas?