Bobafart Posted December 18, 2006 Share Posted December 18, 2006 I am display a bunch of news feeds ( http://www.gabbr.com ) . Some of the newsfeeds have img's at the beginning, other news feeds have 300+ characters.. you can imagine the high variability and heterogeneity that I am having when I display the multiple news feed content.So, I thought I would cut down the size of the news feed articles to only 200 characters. That way I wouldn't have hundreds of words displaying for one article taking up valuable space on the front page. The problem is some of the news articles start with the < img src > tags. So the first 200 characters may, sometimes, muck up the image. I want the images to still display, however I only want the first 200 characters of text to be displayed. I will use substr($article, 0, 200) to only show the first 200 characters.. but how do I position the counter to start counting AFTER the IMG tag IF there is an IMG to be displayed in the feed?Is there was a way to position the counter after the end of the last '>' sign after the <img src></img> tag. Once the counter is there I will then count 200 characters and terminate the article output at that point so that the IMG is still displayed and the article doesn't go on forever.Does anyone know how to do this? Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 [code=php:0]$start = strpos($articel,'>');echo substr($article,$start+1,200);[/code] Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted December 18, 2006 Share Posted December 18, 2006 but wont he get the first one not the second ? because he metioned <img src> and </img>and what if he does like setting the text like <font> or somin? i was thinking soming like [code]<?php#start by putting your info into a array so we can search$array = array($article);if(in_array("<img",$array)) { #cut it down to 100 maybe? $pos = strpos($article,"</img>"); $article2 = substr($article,0,$pos); $article = substr($article,$pos,100); $article = $article . $article2;}else{ $article = substr($article,0,200);}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 [quote]but wont he get the first one not the second ?because he metioned <img src> and </img>[/quote]Yeah, silly me.Could use an offset,[code=php:0]$start = strpos($articel,'>',1);echo substr($article,$start+1,200);[/code]but as you said, there could be other tags. I gues there probably isn't really a safe option here. Yours is probably safer, depends on the data I suppose. Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted December 18, 2006 Share Posted December 18, 2006 it took me forever to make that up too .... i had to do a lot of research because i don't do this kind of stuff Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.