RE: Explode Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That is exactly it.
Thanks James I knew it was simple just forgot how it was done.





Richard L. Buskirk

-----Original Message-----
From: James Yerge [mailto:james@xxxxxxxxxxxxxxx] 
Sent: Tuesday, May 17, 2011 8:51 PM
To: admin@xxxxxxxxxxxxxxxxxxx
Cc: 'Marc Guay'; php-general@xxxxxxxxxxxxx
Subject: Re:  Explode Question

On 05/17/2011 07:53 PM, admin@xxxxxxxxxxxxxxxxxxx wrote:
> The desired result is.
>
> Array
> (
> 	[0] = > "On the";
> 	[1] = > "course or in the";
> 	[2] = > "of colver";
> );
>
> I am just not sure the delimiter can be an array in the Explode function.
>
>
>
>
>
>
> Richard L. Buskirk
>
> -----Original Message-----
> From: Marc Guay [mailto:marc.guay@xxxxxxxxx] 
> Sent: Tuesday, May 17, 2011 7:52 PM
> To: php-general@xxxxxxxxxxxxx
> Subject: Re:  Explode Question
>
>> $one = array(0 =>'golf', 1 => 'field');
>> $two = array(0 => "On the golf course or in the field of clover");
>> $array_exp = explode($one, $two);
> What's the desired result?
>
> array('golf' => "On the golf course or in the field of clover",
> 'field' =>  "On the golf course or in the field of clover")); ?
>
>
> Marc
>

Here's something to mess around with, to fit to your liking.

<?php
$one = array('golf','field');
$two = array("On the golf course or in the field of clover");
$result = array_explode($one,$two);

print_r($result);

function array_explode($delimiters,$array)
{
    if ( !is_array($delimiters) || !is_array($array) ) {
        //bail
        return;
    }
    $string = $array[0];
    $regex = "@(".implode('|',$delimiters).")@";
    return preg_split($regex,$string);
}
?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux