Fender963 Posted December 2, 2006 Share Posted December 2, 2006 Hello everyone,Currently if I want to fetch data I have stored in my database I do a simple $arr=mysql_fetch_array(......)and then $temp = $arr['article'];echo "$article";This however is pretty limiting. I would like to be able to somehow maybe read it character by character or do something so that I could say, insert an ad after the first 500 characters or something of this nature.Any tips? Link to comment https://forums.phpfreaks.com/topic/29179-fetching-data-from-database/ Share on other sites More sharing options...
drifter Posted December 2, 2006 Share Posted December 2, 2006 Well I use this function to put ... after a word after so many characters. function myfragment($s,$n) { $scan=0; while($scan==0){ if(substr($s,$n,1)==' ' || strlen($s)<$n){ $scan=1; }else{ $n++; } } return substr($s,0,$n) . "..."; }lets try this (not tested, just a guess)[code] function myfragments($s,$n,$ad) { $scan=0; while($scan==0){ if(substr($s,$n,1)==' ' || strlen($s)<$n){ $scan=1; }else{ $n++; } } return substr($s,0,$n) . "<br />" . $ad . "<br /> . substr($s,$n); }////Insert $my in $article after the first word ends ater 500 characters//echo myfragments($article,500,$myad);[/code]Hope this works, or at least gives you an idea. Link to comment https://forums.phpfreaks.com/topic/29179-fetching-data-from-database/#findComment-133817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.