copying and pasting, splitting one var into two

From: Date: Sun, 01 Oct 2000 05:47:24 +0000
Subject: copying and pasting, splitting one var into two
Groups: php.general 
Request: Send a blank email to php-general+get-18192@lists.php.net to get a copy of this message
hi, i've got two questions, both are related to reg expressions i guess: 1. okay, i've got $data, for this specific purpose it's the source (headers and all) of an email, but i'd like to know generally how it's done. I want to know a clean way to search for a string, copy it's contents to a new variable... an example would be searching for "From: ... \n" (where ... is unknown content), then to copy "From: ... \n" to a new variable $from. Then I can strip out the "From: " and "\n" then use it for other stuff later. 2. I want to take $data, and split it on "\n\n" into two new variables (say, $headers and $body). Does this code look right? Is there a better way? --- $splitString = "\n\n"; $data = "headersblahblahblahblah\n\nbodyblahbalhblahblah"; list($headers, $body) = split($splitString, $data); echo "Headers: ".$headers."\n".$body."\n"; --- Many thanks, Justin French

« previous php.general (#18192) next »