vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Regex a user name and append to a URL in template? (https://vborg.vbsupport.ru/showthread.php?t=262160)

brdad 04-17-2011 08:41 PM

Regex a user name and append to a URL in template?
 
This is my first post and I'm jumping in head first so please bear with me.

I want to format a user name removing unusable characters, and then append that user name to a URL for IRC chat. I'm not 100% sure I can do this in a template for a widget nor am I 100% sure how to code it. Any help would be appreciated. I know the code below is wrong, but it should be clear what I am trying to accomplish.

Thanks

PHP Code:

<div class="cms_widget"
  <
div class="block"
    <
div class="cms_widget_header widget_header"
       <
h3>IRC Chat</h3
    </
div
  <
div class="cms_widget_content widget_content"

      
Dirty $bbuserinfo[username]

      
$Clean preg_replace('/^[0-9]+([^0-9])/''\\1'preg_replace('/[^-a-zA-Z0-9_|^{}[\]\\\\]/'''$Dirty));}

      
$Output 'http://www.somesite.com/chat&user='$Clean
  

    
</div
   </
div
</
div


Disasterpiece 04-19-2011 07:55 AM

PHP Code:

$cn preg_replace('/^[0-9]+([^0-9])/''\\1'preg_replace('/[^-a-zA-Z0-9_|^{}[\]\\\\]/'''$bbuserinfo["username"]));

$output .= '<a href="http://www.somesite.com/chat&user='.$cn.'">Join Chat!</a>'

try this

no guarantee on that regex operation tough, looks unnecessarily complicated.

brdad 04-19-2011 10:26 AM

Thanks, I think I got it. Part of my problem was trying to do the php in a template instead of a direct exec widget itself.

I did have to split the regex up into two lines. One part has to remove unwanted characters, the other has to remove leading digits, or I have now changed it to add an underscore before leading digits (Still not fully proven, however!)

PHP Code:

$dirty vB::$vbulletin->userinfo['username'];
$clean preg_replace('/[^-a-zA-Z0-9_|^{}[\]\\\\]/','',$dirty);
$cleaner preg_replace('/^([0-9]+)([^0-9])/''_\\1\\2',$clean); 


ecrist 04-22-2011 02:21 AM

For what it's worth, you could do this:

PHP Code:

$clean preg_replace(
     array(
'/[^-a-zA-Z0-9_|^{}[\]\\\\]/','/^([0-9]+)([^0-9])/''_\\1\\2'),
     array(
'''_\\1\\2'), 
     
vB::$vbulletin->userinfo['username']
); 

Sorry, it seems the PHP tags don't want to size the box properly above.


All times are GMT. The time now is 05:02 AM.

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.01320 seconds
  • Memory Usage 1,728KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete