jonaofarc Posted November 23, 2008 Share Posted November 23, 2008 so we have a string like 4+1 I just want the 4 isolated from the + and the 1 any ideas? Link to comment https://forums.phpfreaks.com/topic/133866-how-does-one-remove-everything-after-a-in-a-php-string/ Share on other sites More sharing options...
jonaofarc Posted November 23, 2008 Author Share Posted November 23, 2008 any ideas? Link to comment https://forums.phpfreaks.com/topic/133866-how-does-one-remove-everything-after-a-in-a-php-string/#findComment-696830 Share on other sites More sharing options...
azuka Posted November 23, 2008 Share Posted November 23, 2008 You're not very specific. Under what conditions would you get a string like that? There are many ways, some regex based, some not. At it's simplest I'd use $text = '4+1'; $text = substr($text, 0, 1); or $text = '4+1'; $text = current(explode('+', $text)); Link to comment https://forums.phpfreaks.com/topic/133866-how-does-one-remove-everything-after-a-in-a-php-string/#findComment-696833 Share on other sites More sharing options...
jonaofarc Posted November 23, 2008 Author Share Posted November 23, 2008 thanks azuka , thats all I needed. Link to comment https://forums.phpfreaks.com/topic/133866-how-does-one-remove-everything-after-a-in-a-php-string/#findComment-696840 Share on other sites More sharing options...
redarrow Posted November 23, 2008 Share Posted November 23, 2008 This is the correct way ill do it anyway...... <?php $txt="4+1"; $x=preg_replace("/([1]){1}||([4]){1}/",' ',$txt); echo $x; ?> Link to comment https://forums.phpfreaks.com/topic/133866-how-does-one-remove-everything-after-a-in-a-php-string/#findComment-696844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.