vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   yet another replace issue php, img to div (https://vborg.vbsupport.ru/showthread.php?t=322149)

Dr.CustUmz 03-17-2016 05:05 PM

yet another replace issue php, img to div
 
so i have been playing with this for a couple days, and i still cant get it. im trying to replace the avatar img in postbit to be a div instead.

this is the line to be changed:
Code:

<img src="$post[avatarurl]" $post[avwidth] $post[avheight] alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" />
im hooking into postbit_display_complete

some methods i have used with no results:
PHP Code:

$search '<img src="$post[avatarurl]" $post[avwidth] $post[avheight] alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" />';
$replace '<div id="drcltrav" style="background-color:'.$color.';"><span>'.strtoupper($drcltrav_lgth).'</span></div>';
$vbulletin->templatecache['postbit'] = str_replace($search$replace$vbulletin->templatecache['postbit']);
$show['avatar'] = true

using for my search:
PHP Code:

$search '<img src="' $post[avatarurl] . '" ' $post[avwidth] . ' ' $post[avheight] . 'alt="<phrase 1="' $post[username] . '">' $vbphrase[xs_avatar] . '</phrase>" border="0" />'

this method seemed the most promising since it wouldnt matter if the site has a custom template:
PHP Code:

$pattern '/<img src="'.$post['avatarurl'].'"(.*?)>/';
$replacement '<div id="myDiv">content</div>';

echo 
preg_replace($pattern$replacement$vbulletin->templatecache['postbit']); 

and they're about 50 other ways I have tried this. the ONLY time i get a result is when i use
PHP Code:

$post['avatarurl'] = '" class="someClass'

but i dont just want to add a class to it i want to replace it completely

squidsk 03-17-2016 06:26 PM

Your playing around with regular expressions so you need to escape every non-standard character otherwise they all have particular meanings for the regular expression engine other than their plain text characters.

So your search string would need to be something like:

Code:

'\<img src=\"\$post\[avatarurl\]\" \$post\[avwidth\] \$post\[avheight\] alt=\"\<phrase 1=\"\$post\[username\]\"\>\$vbphrase\[xs_avatar\]\<\/phrase\>\" border=\"0\" \/\>'
The easiest way to test is to use an online preg_replace tester to see if you patterns work or not.

Dr.CustUmz 03-17-2016 06:48 PM

Quote:

Originally Posted by squidsk (Post 2567476)
Your playing around with regular expressions so you need to escape every non-standard character otherwise they all have particular meanings for the regular expression engine other than their plain text characters.

So your search string would need to be something like:

Code:

'\<img src=\"\$post\[avatarurl\]\" \$post\[avwidth\] \$post\[avheight\] alt=\"\<phrase 1=\"\$post\[username\]\"\>\$vbphrase\[xs_avatar\]\<\/phrase\>\" border=\"0\" \/\>'
The easiest way to test is to use an online preg_replace tester to see if you patterns work or not.

so what would i have to escape if i were using
PHP Code:

$pattern '/<img src="'.$post['avatarurl'].'"(.*?)>/'
$replacement '<div id="myDiv">content</div>'

i tried a tester but it threw me errors no matter what i did =/

squidsk 03-17-2016 08:44 PM

Try <img src\="\$post\[avatarurl\]".*/> as the pattern.

Dr.CustUmz 03-17-2016 09:50 PM

PHP Code:

$pattern '<img src\="\$post\[avatarurl\]".*/>';  
$replacement '<div id="myDiv">content</div>'
echo 
preg_replace($pattern$replacement$vbulletin->templatecache['postbit']); 

no luck =(

MarkFL 03-17-2016 10:38 PM

Try the pattern:

PHP Code:

$pattern '/<img src\="\$post\[avatarurl\]".*?\/>/'


Dr.CustUmz 03-17-2016 11:41 PM

again nothing, lol this is becoming such a headache for such a little task =(

--------------- Added [DATE]1458277099[/DATE] at [TIME]1458277099[/TIME] ---------------

just for popped in my head so i tried.

postbit_display_complete
Code:

$search = 'img';
$replace = 'a';

$vbulletin->templatecache['postbit'] = preg_replace($search, $replace, $vbulletin->templatecache['postbit']);

seems like that should do something.... like replace all the images with links, but all it does is cause an infinite load -_-

--------------- Added [DATE]1458322966[/DATE] at [TIME]1458322966[/TIME] ---------------

seems postbit isnt cached in the hook i was using

using
Code:

$vbulletin->templatecache['postbit'] = str_replace('<img src=\"$post[avatarurl]', 'SHIT', $vbulletin->templatecache['postbit']);
in global gave me results. although i need some help to get the "whatever comes after doesnt matter" combination, been playing with it for hours and cant get it =/

example in red:
Code:

str_replace('<img src=\"$post[avatarurl]'\"*/>, ......
so everything in the img tag gets replaced.


All times are GMT. The time now is 03:58 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.01175 seconds
  • Memory Usage 1,753KB
  • 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
  • (6)bbcode_code_printable
  • (7)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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