Destramic Posted January 15, 2011 Share Posted January 15, 2011 what im trying to d is substr a table name just to get the fisrt character so i can use it as an AS...example FROM news AS n $table = "news"; $as = substr($table, 0, 1); sigular named tables are fine...but if the table is named something like this news_comments and have many underscores i want it to return nc...what is the best way to achieve this please? Quote Link to comment https://forums.phpfreaks.com/topic/224510-substr/ Share on other sites More sharing options...
Porl123 Posted January 15, 2011 Share Posted January 15, 2011 <?php $table = "news"; $chars = str_split($table); echo $chars[0]; Quote Link to comment https://forums.phpfreaks.com/topic/224510-substr/#findComment-1159703 Share on other sites More sharing options...
Destramic Posted January 15, 2011 Author Share Posted January 15, 2011 it doesnt work if you do this $table = "news_comments"; $chars = str_split($table); echo $chars[0]; i want it to return NC...the code i written above does the same as yours really Quote Link to comment https://forums.phpfreaks.com/topic/224510-substr/#findComment-1159706 Share on other sites More sharing options...
Porl123 Posted January 15, 2011 Share Posted January 15, 2011 $table = "news_comments"; $split = explode('_',$table); $c = ''; foreach($split as $word) { $s = str_split($word); $c .= $s[0]; } echo $c; Quote Link to comment https://forums.phpfreaks.com/topic/224510-substr/#findComment-1159707 Share on other sites More sharing options...
Destramic Posted January 15, 2011 Author Share Posted January 15, 2011 that works great thank you Quote Link to comment https://forums.phpfreaks.com/topic/224510-substr/#findComment-1159783 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.