vicodin Posted February 18, 2008 Share Posted February 18, 2008 Ok im still pretty new at php so what im trying to accomplish is this: Ok in my string i have things seperated by a "|" what i want to do is get only the first peice of data that is in the first "|" and leave off the rest. If you dont get just say so ill try to refrase it. Thank you!!! Link to comment https://forums.phpfreaks.com/topic/91651-explode-help/ Share on other sites More sharing options...
ratcateme Posted February 18, 2008 Share Posted February 18, 2008 here use substr and strpos $first_part=substr($str,0,strpos('|',$str)); Scott. Link to comment https://forums.phpfreaks.com/topic/91651-explode-help/#findComment-469402 Share on other sites More sharing options...
vicodin Posted February 18, 2008 Author Share Posted February 18, 2008 Now it doesnt show anything. =( Link to comment https://forums.phpfreaks.com/topic/91651-explode-help/#findComment-469406 Share on other sites More sharing options...
ratcateme Posted February 18, 2008 Share Posted February 18, 2008 sorry i had the strpos around the wrong way it should be $first_part=substr($str,0,strpos($str,'|')); Scott. Link to comment https://forums.phpfreaks.com/topic/91651-explode-help/#findComment-469409 Share on other sites More sharing options...
vicodin Posted February 18, 2008 Author Share Posted February 18, 2008 Awesome that worked. But i forgot to include something. Not all of my data that its grabbing from the DB has a "|" because not all have mulitple parts. Those are comming up blank. Any ideas? Thanks again Scott! Link to comment https://forums.phpfreaks.com/topic/91651-explode-help/#findComment-469413 Share on other sites More sharing options...
ratcateme Posted February 18, 2008 Share Posted February 18, 2008 try this <?php if(preg_match('|',$str)){ $first_part=substr($str,0,strpos($str,'|')); }else{ $first_part=$str; } ?> Scott. Link to comment https://forums.phpfreaks.com/topic/91651-explode-help/#findComment-469415 Share on other sites More sharing options...
vicodin Posted February 18, 2008 Author Share Posted February 18, 2008 Thank you!!! Link to comment https://forums.phpfreaks.com/topic/91651-explode-help/#findComment-469418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.