<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: values code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 05:48:11 GMT</pubDate>
    <description>DZone Snippets: values code</description>
    <item>
      <title>PHP: Email All Form Values</title>
      <link>http://snippets.dzone.com/posts/show/4338</link>
      <description>If you need a very basic contact form and don't want to write extra code for putting the value of each field into the email, you can use this basic email. It works best if you name your form fields something legible, such as First_Name&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if (isset($_POST['Submit'])) {&lt;br /&gt;	// Prepare message&lt;br /&gt;	$msg = "Time: " . date("m/d/y g:ia", time()) . "\n";&lt;br /&gt;	foreach ($_POST as $field=&gt;$value) {&lt;br /&gt;		if ($field != "submit") $msg .= $field . ": " . $value . "\n";&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	if (mail("TOEMAIL", "SUBJECT", $msg, "From: FROM_NAME &lt;FROM@ADDRESS.com&gt;")) {&lt;br /&gt;		// Email was sent&lt;br /&gt;	} else {&lt;br /&gt;		// Erro sending email&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jul 2007 23:09:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4338</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>PHP: Pass On Values For A Multi-Page Form</title>
      <link>http://snippets.dzone.com/posts/show/4337</link>
      <description>While the best way to do this involves saving the data into a database and passing an encrypted reference to the next page, this method will suffice for non-critical uses.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;foreach ($_POST as $field=&gt;$value) {&lt;br /&gt;	echo "&lt;input type=\"hidden\" name=\"" . $field . "\" value=\"" . $value . "\" /&gt;";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jul 2007 23:03:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4337</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>CSV Parser / Writer for PHP</title>
      <link>http://snippets.dzone.com/posts/show/3128</link>
      <description>CSV Parser / Writer&lt;br /&gt;&lt;br /&gt;Example A:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//cell separator, row separator, value enclosure&lt;br /&gt;$csv = new CSV(';', "\r\n", '"');&lt;br /&gt;&lt;br /&gt;//parse the string content&lt;br /&gt;$csv-&gt;setContent(file_get_contents('data.csv'));&lt;br /&gt;&lt;br /&gt;//returns an array with the CSV data&lt;br /&gt;print_r($csv-&gt;getArray());&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Exemple B:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$csv = new CSV(';', "\r\n", '"');&lt;br /&gt;//sets up the content through an array&lt;br /&gt;$csv-&gt;setArray(&lt;br /&gt;	array(&lt;br /&gt;		array('col"una1', "colu\r\nna2"),&lt;br /&gt;		array('col;una3', 'coluna4')&lt;br /&gt;	)&lt;br /&gt;);&lt;br /&gt;//retorns string with the CSV representation&lt;br /&gt;print $csv-&gt;getContent();&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com&lt;br /&gt;class CSV{&lt;br /&gt;	var $cellDelimiter;&lt;br /&gt;	var $valueEnclosure;&lt;br /&gt;	var $rowDelimiter;&lt;br /&gt;&lt;br /&gt;	function CSV($cellDelimiter, $rowDelimiter, $valueEnclosure){&lt;br /&gt;		$this-&gt;cellDelimiter = $cellDelimiter;&lt;br /&gt;		$this-&gt;valueEnclosure = $valueEnclosure;&lt;br /&gt;		$this-&gt;rowDelimiter = $rowDelimiter;&lt;br /&gt;		$this-&gt;o = array();&lt;br /&gt;	}&lt;br /&gt;	function getArray(){&lt;br /&gt;		return $this-&gt;o;&lt;br /&gt;	}&lt;br /&gt;	function setArray($o){&lt;br /&gt;		$this-&gt;o = $o;&lt;br /&gt;	}&lt;br /&gt;	function getContent(){&lt;br /&gt;		if(!(($bl = strlen($b = $this-&gt;rowDelimiter)) &amp;&amp; ($dl = strlen($d = $this-&gt;cellDelimiter)) &amp;&amp; ($ql = strlen($q = $this-&gt;valueEnclosure))))&lt;br /&gt;			return '';&lt;br /&gt;		for($o = $this-&gt;o, $i = -1; ++$i &lt; count($o);){&lt;br /&gt;			for($e = 0, $j = -1; ++$j &lt; count($o[$i]);)&lt;br /&gt;				(($e = strpos($o[$i][$j], $q) !== false) || strpos($o[$i][$j], $b) !== false || strpos($o[$i][$j], $d) !== false)&lt;br /&gt;				&amp;&amp; $o[$i][$j] = $q . ($e ? str_replace($q, $q . $q, $o[$i][$j]) : $o[$i][$j]) . $q;&lt;br /&gt;			$o[$i] = implode($d, $o[$i]);&lt;br /&gt;		}&lt;br /&gt;		return implode($b, $o);&lt;br /&gt;	}&lt;br /&gt;	function setContent($s){&lt;br /&gt;		$this-&gt;o = array();&lt;br /&gt;		if(!strlen($s))&lt;br /&gt;			return true;&lt;br /&gt;		if(!(($bl = strlen($b = $this-&gt;rowDelimiter)) &amp;&amp; ($dl = strlen($d = $this-&gt;cellDelimiter)) &amp;&amp; ($ql = strlen($q = $this-&gt;valueEnclosure))))&lt;br /&gt;			return false;&lt;br /&gt;		for($o = array(array('')), $this-&gt;o = &amp;$o, $e = $r = $c = 0, $i = -1, $l = strlen($s); ++$i &lt; $l;){&lt;br /&gt;			if(!$e &amp;&amp; substr($s, $i, $bl) == $b){&lt;br /&gt;				$o[++$r][$c = 0] = '';&lt;br /&gt;				$i += $bl - 1;&lt;br /&gt;			}&lt;br /&gt;			elseif(substr($s, $i, $ql) == $q){&lt;br /&gt;				$e ? (substr($s, $i + $ql, $ql) == $q ?&lt;br /&gt;				$o[$r][$c] .= substr($s, $i += $ql, $ql) : $e = 0)&lt;br /&gt;				: (strlen($o[$r][$c]) == 0 ? $e = 1 : $o[$r][$c] .= substr($s, $i, $ql));&lt;br /&gt;				$i += $ql - 1;&lt;br /&gt;			}&lt;br /&gt;			elseif(!$e &amp;&amp; substr($s, $i, $dl) == $d){&lt;br /&gt;				$o[$r][++$c] = '';&lt;br /&gt;				$i += $dl - 1;&lt;br /&gt;			}&lt;br /&gt;			else&lt;br /&gt;				$o[$r][$c] .= $s[$i];&lt;br /&gt;		}&lt;br /&gt;		return true;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Dec 2006 22:36:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3128</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>swap values without temporary variable</title>
      <link>http://snippets.dzone.com/posts/show/2676</link>
      <description>The XOR swap algorithm is an inefficient method of swapping two variables. http://en.wikipedia.org/wiki/Xor_swap_algorithm&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;void XORSwap(void *x, void *y)&lt;br /&gt;{&lt;br /&gt;   *x ^= *y;&lt;br /&gt;   *y ^= *x;&lt;br /&gt;   *x ^= *y;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 23 Sep 2006 17:40:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2676</guid>
      <author>nevadalife (nevada)</author>
    </item>
  </channel>
</rss>
