split string on multiple char like '+' '-' '*' '/'

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
us2rn4m2
New php-forum User
New php-forum User
Posts: 17
Joined: Thu Aug 09, 2012 1:28 pm

Re: split string on multiple char like '+' '-' '*' '/'

Post by us2rn4m2 » Fri Sep 14, 2012 1:52 pm

Hi,

Something like this ?

Code: Select all

<?php

$a = "67* 90+ 86 -23";
$b = str_split($a, 2);

echo '<pre>';
print_r($a);
echo '</pre>';

/* Result:	
	Array
	(
		[0] => 67
		[1] => * 
		[2] => 90
		[3] => + 
		[4] => 86
		[5] =>  -
		[6] => 23
	)	
 */

$c = '';

foreach($b as $key => $value) {
	$v  = trim($value);
	$c .= " '$v' ";
}

echo $c;
//	Result: '67' '*' '90' '+' '86' '-' '23'

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests