Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2007, 10:31 AM
humax9110 humax9110 is offline
 
Join Date: Jun 2003
Location: BAHRAIN
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default need help for .... ereg_replace ... to replace number

hello every body,

I want to replce the number (between 7 to 11 digit) to (U can't post number) by using ereg_replace

I made this

$message = ereg_replace('[0-9]{7,11}','(u can't post number)',$message);

but this will replace all number even that 1234678.gif or 12345678.jpg

what I want that to replace only sprate number Neither *12345678 nor 12345678* mean if there is char. before or after number not replace the number ....

Thanks ...
Reply With Quote
  #2  
Old 05-02-2007, 04:21 AM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Take a look at the lookaround syntax described here: http://www.regular-expressions.info/refadv.html

You could use something like this:

'[\d]{7,11}(?![\d]+)'

This uses a zero-length look ahead.

The problem with the look-behind is that some regex engines only allow plain text in the look-behind.

But, if you know what could be before the number you are matching, you could craft that into the regex.

I am sure there is a simpler way....
Reply With Quote
  #3  
Old 05-02-2007, 09:31 AM
humax9110 humax9110 is offline
 
Join Date: Jun 2003
Location: BAHRAIN
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ElfMage View Post
Take a look at the lookaround syntax described here: http://www.regular-expressions.info/refadv.html

You could use something like this:

'[\d]{7,11}(?![\d]+)'

This uses a zero-length look ahead.

The problem with the look-behind is that some regex engines only allow plain text in the look-behind.

But, if you know what could be before the number you are matching, you could craft that into the regex.

I am sure there is a simpler way....
Thanks ...

before number not characters or = or :

after number not characters or .

I Waited for ur help :up:
Reply With Quote
  #4  
Old 05-03-2007, 03:16 AM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default



You can do this:
PHP Code:
$message preg_replace
       
'#([^a-z\=\:]*)[\d]{7,11}([^\w\.]*)#si'
        
'\1u can\'t post numbers\2'
        
$message
    
); 
I used preg_replace because I am more familiar with that, but you can easily adapt the patterns to ereg_replace.

Basically what the code above is (supposed to be) doing is:

* Find any series of characters that are not characters, = or : (0 or more), and capture that into \1
* Followed by 7 to 11 digits (not captured)
* Followed by any non-character or ., and capture it into \2

And then replace that with the captured groups \1, your message, and \2.

I think that you mentioned in your last post differs from your original post, but you get the idea, you can change this to suit your needs.
Reply With Quote
  #5  
Old 05-03-2007, 10:06 AM
humax9110 humax9110 is offline
 
Join Date: Jun 2003
Location: BAHRAIN
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ElfMage View Post


You can do this:


I used preg_replace because I am more familiar with that, but you can easily adapt the patterns to ereg_replace.

Basically what the code above is (supposed to be) doing is:

* Find any series of characters that are not characters, = or : (0 or more), and capture that into \1
* Followed by 7 to 11 digits (not captured)
* Followed by any non-character or ., and capture it into \2

And then replace that with the captured groups \1, your message, and \2.

I think that you mentioned in your last post differs from your original post, but you get the idea, you can change this to suit your needs.
Thanks for ur trying to help me ... but
what I need it is diffrent

PHP Code:
$post['message'] = preg_replace
       
'#([^a-z\=\:]*)[\d]{7,11}([^\w\.]*)#si'
        
'\1u can\'t post numbers\2'
        
$post['message']
    ); 
This will replace 12345678.gif to can't post numbers and this what I don't want it ...


I don't want replace these

1234567.gif
123455678.jpg
1245663.swf
=12345678
Reply With Quote
  #6  
Old 05-03-2007, 11:34 AM
magnus's Avatar
magnus magnus is offline
 
Join Date: Apr 2002
Location: Miami, FL
Posts: 1,107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="http://www.regular-expressions.info/anchors.html" target="_blank">Use anchors.</a>
Reply With Quote
  #7  
Old 05-04-2007, 05:29 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hows about...
PHP Code:
$post['message'] = preg_replace
       
'/([^|[^a-z0-9=:])[0-9]{7,11}($|[^\.a-z0-9])/si'
        
'\1u can\'t post numbers\2'
        
$post['message']
    ); 
Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:23 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03873 seconds
  • Memory Usage 2,234KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete