Current location: Hot Scripts Forums » Programming Languages » PHP » using a php function in prg_replace function


using a php function in prg_replace function

Reply
  #1 (permalink)  
Old 10-15-06, 02:25 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
using a php function in prg_replace function

Ive been looking for it and cannot find on how to add the highlight_string function to a preg_replce(); function.

my replace string is...
'<strong>PHP Code:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>'. highlight_string('\1') .'</em></div>'

but it outputs 1 in the <div> tag :-/

any other ideas?
Reply With Quote
  #2 (permalink)  
Old 10-15-06, 02:38 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You need either two slashes infront of the one (\\1), or use $1.

EDIT:
I don't think this wil work this way though.

EDIT 2:
You need to set the second argument in highlight_string() to true in order to get the code as string.

And this might help.
http://www.programmingtalk.com/showthread.php?t=32549

Last edited by nico_swd; 10-15-06 at 02:48 PM.
Reply With Quote
  #3 (permalink)  
Old 10-15-06, 02:49 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
okay...

thank you very much! but it does the same thing

[PHP]$patterns = array( '`\[b\](.+?)\[/b\]`is',
'`\[i\](.+?)\[/i\]`is',
'`\[u\](.+?)\[/u\]`is',
'`\[strike\](.+?)\[/strike\]`is',
'`\[color=#([0-9]{6})\](.+?)\[/color\]`is',
'`\[color=(.+?)\](.+?)\[/color\]`is',
'`\[email\](.+?)\[/email\]`is',
'`\[img\](.+?)\[/img\]`is',
'`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
'`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
'`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',
'`\[quote\](.+?)\[/quote\]`is',
'`\[indent](.+?)\[/indent\]`is',
'`\[size=([1-6]+)\](.+?)\[/size\]`is',
'`\[code](.+?)\[/code\]`is',
'`\
PHP Code:

(.+?)\[/php\]`is'

                        );
    
    
$replaces =  array(
                        '<strong>\\1</strong>',
                        '<em>\\1</em>',
                        '<span style="border-bottom: 1px dotted">\\1</span>',
                        '<strike>\\1</strike>',
                        '<span style="color:#\1;">\2</span>',
                        '<font color=\1>\2</font>',
                        '<a href="mailto:\1">\1</a>',
                        '<img src="\1" alt="" style="border:0px;" />',
                        '<a href="\1\2">\6</a>',
                        '<a href="\1\2">\1\2</a>',
                        '<a href="http://\1">\1</a>',
                        '<strong>Quote:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>\1</em></div>',
                        '<pre>\\1</pre>',
                        '<h\1>\2</h\1>',
                        '<strong>Code:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>\1</em></div>',
                        '<strong>PHP Code:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>'. highlight_string("$1") .'</em></div>'
                        ); 
Reply With Quote
  #4 (permalink)  
Old 10-16-06, 04:01 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
nope that didnt work either...

:-/ any other ideas?
Reply With Quote
  #5 (permalink)  
Old 10-16-06, 04:10 PM
stormshadow's Avatar
stormshadow stormshadow is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
nvrm

i got a code from php.net... thanks ^_^
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP upload prob minority ASP 1 06-27-05 08:35 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
accessing existing ISP email with a PHP webmail script. nlancaster PHP 1 01-07-04 03:28 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 05:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.