<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: php code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 08 Sep 2008 06:06:59 GMT</pubDate>
    <description>DZone Snippets: php code</description>
    <item>
      <title>PHP clean string for mysql</title>
      <link>http://snippets.dzone.com/posts/show/1507</link>
      <description>// Function to clean up a string before using it in a mysql query&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function clean_for_mysql($string,$max_length) {        &lt;br /&gt;  $in_string = ltrim($string);       &lt;br /&gt;  $in_string = rtrim($in_string);&lt;br /&gt;  if (round($max_length) &lt; 1) {  &lt;br /&gt;    $max_length = 131072; // 128K&lt;br /&gt;  }&lt;br /&gt;  if (strlen($in_string) &gt; $max_length) {&lt;br /&gt;    $new_string = substr($in_string,0,$max_length);&lt;br /&gt;  }&lt;br /&gt;  $new_string = mysql_real_escape_string($new_string);&lt;br /&gt;  return $new_string;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Feb 2006 09:48:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1507</guid>
      <author>mvidberg ()</author>
    </item>
    <item>
      <title>PHP filename bad character filter</title>
      <link>http://snippets.dzone.com/posts/show/1506</link>
      <description>// Function to filter out bad characters in a given filename&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function replace_bad_filename_chars($filename) {&lt;br /&gt;  $filtered_filename = "";&lt;br /&gt;&lt;br /&gt;  $patterns = array(&lt;br /&gt;    "/\s/", # Whitespace&lt;br /&gt;    "/\&amp;/", # Ampersand&lt;br /&gt;    "/\+/"  # Plus&lt;br /&gt;  );&lt;br /&gt;  $replacements = array(&lt;br /&gt;    "_",   # Whitespace&lt;br /&gt;    "and", # Ampersand&lt;br /&gt;    "plus" # Plus&lt;br /&gt;  );&lt;br /&gt;  &lt;br /&gt;  $filename = preg_replace($patterns,$replacements,$filename);&lt;br /&gt;  for ($i=0;$i&lt;strlen($filename);$i++) {&lt;br /&gt;    $current_char = substr($filename,$i,1);&lt;br /&gt;    if (ctype_alnum($current_char) == TRUE || $current_char == "_" || $current_char == ".") {&lt;br /&gt;      $filtered_filename .= $current_char;&lt;br /&gt;    }&lt;br /&gt;  }     &lt;br /&gt;        &lt;br /&gt;  return $filtered_filename;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Feb 2006 09:43:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1506</guid>
      <author>mvidberg ()</author>
    </item>
    <item>
      <title>PHP dollar format</title>
      <link>http://snippets.dzone.com/posts/show/1505</link>
      <description>// Function to return amount in the format $#.##&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function dollar_format($amount) {&lt;br /&gt;  $new_amount = "\$".sprintf("%.2f",$amount);&lt;br /&gt;  return $new_amount;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Feb 2006 09:38:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1505</guid>
      <author>mvidberg ()</author>
    </item>
    <item>
      <title>PHP email validation function</title>
      <link>http://snippets.dzone.com/posts/show/1504</link>
      <description>// Simple function to check if an given email adddress is valid&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function is_valid_email($email) {&lt;br /&gt;  $result = TRUE;&lt;br /&gt;  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {&lt;br /&gt;    $result = FALSE;&lt;br /&gt;  }&lt;br /&gt;  return $result;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Feb 2006 09:31:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1504</guid>
      <author>mvidberg ()</author>
    </item>
  </channel>
</rss>
