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 01-22-2004, 11:57 AM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default str_replace/eregi_replace in msg // looped.

Since Xenon and NTLDR helped me with the SQL searching problem (again, thankies much guys. ) I've been attempting to play with foreach and while.

I'm already aware of eregi_replace and str_replace and they work beautifully, however for the life of me I can't seem to get this replacement loop down.

I'd like for $message and str_replace (or eregi_replace) with a SQL table called $cc to filter and output the loop.

The $cc table contains an auto-incrementing field called tagid.

The term to be searched for in $message is $cc[tags]. It's replacement is $cc[tagsname].

Again, it's not the eregi or str_replace that's killing me.. this example works:

PHP Code:
$message eregi_replace("$cc[tags]","$cc[tagsname]",$message); 
But the loop for this to keep reading through each $cc[tags] has me tied. The foreach function I had came out with a big goose egg -- 0, and while wanted to loop continuously.

Any suggestions?
Reply With Quote
  #2  
Old 01-22-2004, 12:12 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm a little confussed on what you are trying to do. Firstly I assume that $cc['tag'] and $cc['tagname'] are variables with a value assigned? If $message is just a string then it should replace all instances of $cc['tag'] within the string, you shouldn't need to loop.
Reply With Quote
  #3  
Old 01-22-2004, 03:58 PM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's the thing. I thought that was true, too, and because of that I'm confused out of my wits. But lemme see if I can explain the situation a little better to see if there's any way to go about this in the way it's currently setup. If not I'll try a different method.

This is how the db looks, per field: (layout: id#, tag to search for, output in msg)

Code:
1, -review-, This is the review tag.
2, -reviewimg-, This is the reviewimg tag.
$cc[tagid], $cc[tags], $cc[tagsname]

All of this information can be added/removed from the admincp. I've created a menu that does so.

So here we are, two tags that should be replaced. FYI, The desired place of outcome is the postbit if this helps.


So on viewing the postbit with the eregi'd/str_replace'd entries.. only the first tag replaced itself.

-review-, output: This is the review tag.

-reviewimg-, output: -reviewimg-.


One tag does replace, but the other doesn't. And that's why I was assuming there'd have to be some sort of a loop involved.
Reply With Quote
  #4  
Old 01-23-2004, 02:05 AM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Harlequin try this for the loop.

PHP Code:
$tags $DB_site->query "SELECT * FROM TABLE_NAME_HERE " ) ;
while ( 
$tag $DB_site->fetch_array $tags ) ) :
    
$message eregi_replace $tag['tags'], $tag['tagsname'], $message ) ;
endwhile ; 
You just have to edit TABLE_NAME_HERE with the table name that you're selecting the tag data from, hope that helps.

Cheers,
g-force2k2
Reply With Quote
  #5  
Old 01-23-2004, 02:56 AM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for the solution, g-force2k2. I don't know why I didn't think of it sooner.

I've been coding on another hack that uses this solution [aside from the journal hack located in the signature]. What kills me is my version of the journal hack has several instances that I've even coded in myself for similiar functions and I still came here to ask this question. Am I the only one that idioticly does this? Please tell me I'm not the only person who doesn't have all the screws tightened with the elevator not quite reaching the top floor. :P

Does it help matters that I work on code until the wee hours of the morning whenever people should be in bed and I'm still staring at the screen like a zombie?

I think I need to catch more z's. x.x

Anyway, again, thank you NTLDR and g-force2k2. Your time is much appreciated.
Reply With Quote
  #6  
Old 01-27-2004, 07:34 AM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<< moved to a new thread -- off-topic to this thread. >>
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 09:35 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04278 seconds
  • Memory Usage 2,214KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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_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