xionhack Posted April 17, 2009 Share Posted April 17, 2009 Hello. I have a string. I want to check if that string has a comma. If it has then to put quotes at the beginning and the end of the string, if it doesnt, then just to save the string. Link to comment https://forums.phpfreaks.com/topic/154555-put-quotes-in-the-beginning-and-the-end/ Share on other sites More sharing options...
kenrbnsn Posted April 17, 2009 Share Posted April 17, 2009 Something like this: <?php $str = (strpos($str,',') !== false)?"'" . $str . "'":$str; ?> Ken Link to comment https://forums.phpfreaks.com/topic/154555-put-quotes-in-the-beginning-and-the-end/#findComment-812706 Share on other sites More sharing options...
soak Posted April 17, 2009 Share Posted April 17, 2009 If you're reading or writing a csv file then PHP (since 5.1) has built in functions that make it really easy: fputcsv and fgettcsv Link to comment https://forums.phpfreaks.com/topic/154555-put-quotes-in-the-beginning-and-the-end/#findComment-812715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.