RE: Text Parser

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

 



<?php
$items = "house , ball , door , roof , floor";

$itemsexploded = Explode(" , ", $items);

$itemsimploded = "'" . implode("','",$itemsexploded) . "'";
?>


That should do it.  The only weird bit is adding the single quotes to the beginning and end of the final string.


You could also do a str_replace()


<?
$items = "house , ball , door , roof , floor";

$finalitems = "'" . Str_replace(" , ", "',', $items) . "'";
?>

And of course you can do regex stuff, but I'm not good at that so I'll leave an example to someone else if they care to give one.


Just remember, explode() creates an array out of items based on a set of characters you tell it are the divider.  If you had a tab delimited text file, you'd want to break on "\t" (for tab).

Implode() does the opposite.  It takes an array and joins the items using the string you give it.   This is good for things like what you're doing above, but in this case a simple str_replace() works just as good too.


-TG


> -----Original Message-----
> From: Pablo D Marotta [mailto:Pablo.D.Marotta@xxxxxxxx] 
> Sent: Thursday, December 02, 2004 10:12 AM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Text Parser
> 
> 
> Hi there..
> A newbie issue:
> I´m receiving this: "house , ball , door , roof , floor"
> And I want to obtain this: "'house','ball','door','roof','floor'"
> 
> Maybe, I should use implode or explode, but I just can´t 
> figure out how..
> Help?
> 
> 
> 
> American Express made the following
>  annotations on 12/02/04 08:13:28
> --------------------------------------------------------------
> ----------------
> **************************************************************
> ****************
> 
>      "This message and any attachments are solely for the 
> intended recipient and may contain confidential or privileged 
> information. If you are not the intended recipient, any 
> disclosure, copying, use, or distribution of the information 
> included in this message and any attachments is prohibited.  
> If you have received this communication in error, please 
> notify us by reply e-mail and immediately and permanently 
> delete this message and any attachments.  Thank you."
> 
> **************************************************************
> ****************
> 
> ==============================================================
> ================
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
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