Public snipts »
Tram's
snipts
showing 1-4 of 4 snipts
-
∞ Strip a string
<?php public static function stripText($text) { // rewrite critical characters // French $text = str_replace(array('À', 'Â', 'à', 'â'), 'a', $text); $text = str_replace(array('É', 'È', 'Ê', 'Ë', 'é', 'è', 'ê', 'ë'), 'e', $text); $text = str_replace(array('Î', 'Ï', 'î', 'ï'), 'i', $text); $text = str_replace(array('Ô', 'ô'), 'o', $text); $text = str_replace(array('Ù', 'Û', 'ù', 'û'), 'u', $text); $text = str_replace(array('Ç', 'ç'), 'c', $text); // German $text = str_replace(array('Ä', 'ä'), 'ae', $text); $text = str_replace(array('Ö', 'ö'), 'oe', $text); $text = str_replace(array('Ü', 'ü'), 'ue', $text); $text = str_replace('ß', 'ss', $text); // Spanish $text = str_replace(array('Ñ', 'ñ'), 'n', $text); $text = str_replace(array('Á', 'á'), 'a', $text); $text = str_replace(array('Í', 'í'), 'i', $text); $text = str_replace(array('Ó', 'ó'), 'o', $text); $text = str_replace(array('Ú', 'ú'), 'u', $text); // Polish $text = str_replace(array('?', '?'), 'a', $text); $text = str_replace(array('?', '?'), 'c', $text); $text = str_replace(array('?', '?'), 'e', $text); $text = str_replace(array('?', '?'), 'l', $text); $text = str_replace(array('?', '?'), 'n', $text); $text = str_replace(array('?', '?'), 's', $text); $text = str_replace(array('Ó', 'ó'), 'o', $text); $text = str_replace(array('?', '?', '?', '?'), 'z', $text); // strip all non word chars $text = preg_replace('/[^a-z0-9_-]/i', ' ', $text); // strtolower is not utf8-safe, therefore it can only be done after special characters replacement $text = strtolower($text); // replace all white space sections with a dash $text = preg_replace('/\ +/', '-', $text); // trim dashes $text = preg_replace('/\-$/', '', $text); $text = preg_replace('/^\-/', '', $text); return $text; }
-
∞ Symfony - Action for text image generation (using GD)
<?php public function executeGenerateText (sfWebRequest $request) { $font = '/images/ROTISSAS.TTF'; $bbox = imageftbbox(20, 0, $font, $this->getRequestParameter('text') ); $width = $bbox[2] - $bbox[0] + 10; $height = $bbox[1] - $bbox[7] + 10; $im = imagecreatetruecolor($width, $height); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); // Set the background to be white // Path to our font file // First we create our bounding box imagefilledrectangle($im, 0, 0, $width, $height, $black); // This is our cordinates for X and Y $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2); //$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) + 3 ; $y = 28; imagefttext($im, 20, 0, 0, $y, $white, $font, $this->getRequestParameter('text')); // Output to browser header('Content-type: image/png'); imagepng($im); imagedestroy($im); return sfView::NONE; }//executeGenerateText ?> # USAGE <img src="<? echo url_for('modulename/generateText?text=My text'); ?>" alt="" title="" />
-
∞ symfony 1.2 - Add a custom filter field for generated admin
<?php public function configure() { $this->widgetSchema['title'] = new sfWidgetFormFilterInput(); $this->validatorSchema['title'] = new sfValidatorPass(array('required' => false)); }//configure public function getFields() { return array_merge(array( 'title'=> 'Title', ), parent::getFields() ); } //getFields protected function addTitleColumnCriteria(Criteria $criteria, $field, $values) { // $values['text'] contains the field value, use it to change $criteria object // es. $criteria->add ('column', $values['text']) }//addTitleColumnCriteria ?>
-
∞ symfony 1.2 - validation for a date range, with 'to date' field not mandatory.
<?php # use it into configure() method in a myForm.class.php file $this->validatorSchema->setPostValidator( new sfValidatorOr( array ( new sfValidatorAnd( array ( new sfValidatorSchemaCompare ('from_date', sfValidatorSchemaCompare::NOT_EQUAL, null ), new sfValidatorSchemaCompare ('to_date', sfValidatorSchemaCompare::EQUAL, null ) )) , new sfValidatorSchemaCompare('from_date', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'to_date',array('throw_global_error' => false), array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")' )) ))); ?>



Web Database Applications with PHP & MySQL