How To Trim Whitespace From Exploded Elements In PHP
Here is a one-liner that explodes a string and trims whitespace from each element: $array = array_map(‘trim’,explode(‘,’,$str));
Here is a one-liner that explodes a string and trims whitespace from each element: $array = array_map(‘trim’,explode(‘,’,$str));
$lastDay = date(“Y-m-t”, strtotime(“-3 months”)); $firstDay = date(“Y-m-01”, strtotime(“-3 months”));
Using Perl: use HTML::Entities; my $plainText = decode_entities(‘Put text to convert here’); Using PHP: $plainText = html_entity_decode(‘Put text to convert here’,ENT_QUOTES,’UTF-8′);
set_include_path(get_include_path().PATH_SEPARATOR.'{DESIRED_NEW_PATH_TO_ADD}’);
Perl to the Rescue! This perl script cleans just one type of infection as an example. Vary the script to search for and clean other combinations and patterns. Also, the script is deliberately written long-hand and verbose, and could be significantly more compact and efficient. It was done this way for ease of use and […]
Safely move a file in PHP:
1 2 3 |
if (copy("/your/source/file","/your/destination/newfile")) { unlink("/your/source/file"); } |
Inside class “yourClassA” calling “yourClassB”:
1 2 3 4 |
class yourClassA { $classObject = new yourClassB; $classObject->setClass($this); } |
Inside class “yourClassB” getting the call from “yourClassA”:
1 2 3 4 5 6 7 8 9 10 |
class yourClassB { public function setClass($object = NULL) { if(is_object($object) and $object instanceof yourClassA) { $this->RefToClassA = $object; $this->yourVar = $RefToClassA->otherVar; // etc, etc, etc... } } } |
The PHP
1 2 3 4 5 6 7 8 9 |
$sql = 'select * from yourTable'; $result = mysql_query($sql); $rows = array(); while ($row = mysql_fetch_assoc($result)) { $rows[] = $row; } $page = new Smarty(); $page->assign('rows', $rows); $page->show('yourTemplate.php'); |
The Smarty Template
1 2 3 4 5 6 7 8 9 10 11 |
{if $rows} {section name=row loop=$rows} {foreach from=$rows[row] key="Key" item="Value"} <p>{$Key}: {$Value}</p> {/foreach} {/section} {else} <h1>NO ROWS FOUND</h1> {/if} |
1 2 3 4 5 6 7 8 9 |
public function valid($function = '') { $methodVariable = array($this, $function); if (is_callable($methodVariable)) { return $this->{$function}(); } else { $this->msgs[] = "Validation method $function is unavailable!"; return 0; } } |
You must use all three lines together for it to work…YMMV:
1 2 3 |
$escaped = str_replace(chr(10),'\n',$original_value); $escaped = str_replace(chr(13),'\r',$escaped); $escaped = preg_replace("/(\r?\n)/","\n",$escaped); |