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!!! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
vicodin Posted February 18, 2008 Author Share Posted February 18, 2008 Now it doesnt show anything. =( Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
vicodin Posted February 18, 2008 Author Share Posted February 18, 2008 Thank you!!! 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.