fer0an Posted March 1, 2010 Share Posted March 1, 2010 hi I've title of my content that sometimes is too long. I want select first 20 char then insert it into my db. any solution? Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/ Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 substr($content,0,20) Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019761 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 $string = substr($string,0,"20"); Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019762 Share on other sites More sharing options...
fer0an Posted March 1, 2010 Author Share Posted March 1, 2010 $string,0,"20" or $string,"0","20" or $string,0,20 which one is correct? Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019766 Share on other sites More sharing options...
fer0an Posted March 1, 2010 Author Share Posted March 1, 2010 how I can say do it after five "-" char? Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019770 Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 $newstring = substr($oldstring,0,20); Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019772 Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 counting "-" in the string is an entirely different matter. you would need to find the position of the 5th - and then adjust the length accordingly Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019773 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 how I can say do it after five "-" char? try explode and break your long string then count string length $pieces = explode("-", $string); Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019774 Share on other sites More sharing options...
fer0an Posted March 1, 2010 Author Share Posted March 1, 2010 I've same as this title : PaaS-Platform-and-Storage-Management-Specialist-Level-Complete-Certification-Kit-Platform-as-a-Service-Study I want select first 5 word that's seprated by "-". any solution? Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019775 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 I've same as this title : PaaS-Platform-and-Storage-Management-Specialist-Level-Complete-Certification-Kit-Platform-as-a-Service-Study I want select first 5 word that's seprated by "-". any solution? $pieces = explode("-", $string); echo "$pieces[0]"; o/p PaaS for five echo "$pieces[0]-$pieces[1]-$pieces[2]-$pieces[3]-$pieces[4]-$pieces[5]"; Link to comment https://forums.phpfreaks.com/topic/193748-select-first-20-char-and-insert/#findComment-1019776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.