code

preg_replace examples

()

Useage

preg_replace ( search_for, replace_with, your_data , optional_limit, optional_count )

Examples


$data = "The cat likes to sit on the fence. He also likes to climb the tree.";

$find ="/the/";
$replace ="a";

//1. replace single word
Echo "$data 
"; Echo preg_replace ($find, $replace, $data); //create arrays

Programmatically add, validate, and theme a node

()

How to have a block display a form created with forms api, and how to theme it:

// add this to the block:
// «?php echo newsletter_signup() ?»

// add this code in (reddirt).module:

function newsletter_signup() {
 // Get our custom made form which will be added through drupal_execute
  $form = drupal_get_form('newsletter_signup_form');
  return $form;
}

function newsletter_signup_form_validate($form, &$form_state) {
  $email = $form_state['values']['email'];
  $birthdate = $form_state['values']['birthdate'];
  
  if (!valid_email_address($email)) {
  

Child Menus don't work, even when 'expand' is forced

()

Using the $primary_links variable in page.tpl.php doesn’t include the child items, even when Expanded is selected in the Drupal menu config. I tried a number of different theme functions, but nothing seemed to work. What did work finally was calling from the page.tpl.php

    print theme('menu_tree','primary-links');

For the id, I used the template.php function:

    function phptemplate_menu_tree($tree) {
      $id=strpos($tree,'href="/"')!==FALSE?' id="primarylinks"':'';
      return '';
    }

wordpress blog stats