GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Jun-2003, 15:24
Allowee's Avatar
Allowee Allowee is offline
Regular Member
 
Join Date: May 2003
Location: The Netherlands
Posts: 339
Allowee has a spectacular aura about

A 'not' regex


I got this code here..
PHP Code:

<?php$message['body'] = preg_replace('_\[php\](.*?)\[/php\]_ise', "parseEmoticons('$1')", $message['body']);?>

but that will only parse emoticons when there are php tags.

I'm looking for a 'not' code.

so when there isn't a php code tag it will parse, and not in the php tags.

just look at the code below......

PHP Code:

<?phpecho ":)";// test :( [this is : ( ]?>

__________________
Pastebin
PHP Documentation Site
Allowee's Blog http://allowee.net
  #2  
Old 07-Jun-2003, 20:20
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

A real simple BBCode suggestion


I have not found an easier way to do what you're trying to do but for now this is what I can suggest.

PHP Code:

<?php
// this array will store the markers and the replacements
$replacements = array();

// the list of smilies and their replacements
$smilies = array(
 ':)'=>'<img src="images/smilies/smile.gif" border="0" alt="">',
 ':('=>'<img src="images/smilies/frown.gif" border="0" alt="">'
);

// do the code highlighting first and place markers
$message['body'] = preg_replace('_\[php\](.*)\[/php\]_ise', "parsePHP('$1')", $message['body']);
// do the smilies
$message['body'] = strtr( $message['body'], $smilies );

// lastly, replace markers with whatever is in $replacements
$message['body'] = strtr( $message['body'], $replacements );

// unset large arrays
unset( $smilies, $replacements );

// the function parsePHP()
function parsePHP( $str )
{
  $mark = marker( 'PHP' );
  $str = highlight_string( $str, 1 );
  // add the marker and highlighted code into our $replacements array
  $GLOBALS['replacements']["$mark"] = $str;
  return $mark;
}

// the function marker()
function marker( $name )
{
  static $counter;
  ++$counter;
  return ( '['.$name.$counter.']' );
}
?>

 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I hate Regex... Elmseeker MySQL / PHP Forum 3 25-Jun-2003 10:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:28.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.