cosmicsea Posted November 29, 2010 Share Posted November 29, 2010 Im using this code right here for to explode titles in my search engine into individual click-able tags <?php $tobeOmitted=array('stuff'); $tagss = explode(" ", str_replace('-', ' ', $title1)); foreach( $tagss as $key => $value){ if(!in_array($value,$tobeOmitted)) echo "<a href='/search.php?query=$value&search=1' target='rel' title='View search results in new window'> $value</a>"; } } ?> Is there a way I can limit the number of tags for each title to 3? I dont want over 100 links on my page because it looks bad in google so I am trying to cut down some pages that have up to 200 links because of long titles and this would cut things down drastically. Any help is appreciated and thank you. Link to comment https://forums.phpfreaks.com/topic/220114-display-only-3-tags/ Share on other sites More sharing options...
intellix Posted November 29, 2010 Share Posted November 29, 2010 I guess you could do $tagss = explode(" ", str_replace('-', ' ', $title1)); $tagss = array($taggs[0],$taggs[1],$taggs[2]); I think that's what you want? Link to comment https://forums.phpfreaks.com/topic/220114-display-only-3-tags/#findComment-1140811 Share on other sites More sharing options...
cosmicsea Posted November 29, 2010 Author Share Posted November 29, 2010 I guess you could do $tagss = explode(" ", str_replace('-', ' ', $title1)); $tagss = array($taggs[0],$taggs[1],$taggs[2]); I think that's what you want? That seems to work great, just had to change your typos on taggs. Thanks alot. Link to comment https://forums.phpfreaks.com/topic/220114-display-only-3-tags/#findComment-1140812 Share on other sites More sharing options...
intellix Posted November 29, 2010 Share Posted November 29, 2010 Copy and pasted yours np! Link to comment https://forums.phpfreaks.com/topic/220114-display-only-3-tags/#findComment-1140817 Share on other sites More sharing options...
intellix Posted November 29, 2010 Share Posted November 29, 2010 Also just from reading another thread I realise that there's also a function for it: http://www.php.net/array_slice $array = array(1,2,3,4,5,6); $array = array_slice($array,0,3); Link to comment https://forums.phpfreaks.com/topic/220114-display-only-3-tags/#findComment-1140824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.