Jump to content

Recommended Posts

Please be easy with me as I am new to this, so I will try to explain as best as I can.

 

In my php file I have used this:

	$vbulletin->templatecache['navbar']= preg_replace(
                                            	$search[1] = '#(<li>|<li\s*class="selected">)*<a\s*class="navtab"\s*href="search\.php\?\'\s*\.\s*\$session\[\'sessionurl\'\]\s*\.\s*\'do=\w+&contenttype=\w+"\s*accesskey="\d">\'\s*\.\s*vB_Template_Runtime::parsePhrase\("\w*"\)\s*\.\s*\'</a>(</li>)*#i','',$vbulletin->templatecache['navbar']);

 

Which searches my output for these html codes:

<li  class="selected"><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getnew&contenttype=vBForum_Post" accesskey="2">{vb:rawphrase getnew_tab}</a>

<li  class="selected"><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getdaily&contenttype=vBForum_Post" accesskey="2">{vb:rawphrase getnew_tab}</a>

<li><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getnew&contenttype=vBForum_Post" accesskey="2">{vb:rawphrase getnew_tab}</a></li>

<li><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getdaily&contenttype=vBForum_Post" accesskey="2">{vb:rawphrase getnew_tab}</a></li>

 

What that does is hide those four lines and works as intended.

 

Now what I want to do is with another option, search for those four codes, and have the output look like this:

<li  class="selected"><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getnew&contenttype=vBForum_Post" accesskey="2"><img src="dbtech/vbnavtabs/images/whats_new_image/whats_new.png"  style="margin-bottom:.25em; vertical-align:middle;' . $image_padding . '" >{vb:rawphrase getnew_tab}</a>

<li  class="selected"><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getdaily&contenttype=vBForum_Post" accesskey="2"><img src="dbtech/vbnavtabs/images/whats_new_image/whats_new.png"  style="margin-bottom:.25em; vertical-align:middle;' . $image_padding . '" >{vb:rawphrase getnew_tab}</a>

<li><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getnew&contenttype=vBForum_Post" accesskey="2"><img src="dbtech/vbnavtabs/images/whats_new_image/whats_new.png"  style="margin-bottom:.25em; vertical-align:middle;' . $image_padding . '" >{vb:rawphrase getnew_tab}</a></li>

<li><a class="navtab" href="search.php?{vb:raw session.sessionurl}do=getdaily&contenttype=vBForum_Post" accesskey="2"><img src="dbtech/vbnavtabs/images/whats_new_image/whats_new.png"  style="margin-bottom:.25em; vertical-align:middle;' . $image_padding . '" >{vb:rawphrase getnew_tab}</a></li>

 

I have tried numerous ways, but can not get it to function, if someone could tell me the code I need to use as I am at a loss. Any help would be greatly appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/253355-preg_replace-help/
Share on other sites

Hi ozzy47,

 

If I have understood, you just want to insert an image tag in the other tags, is that right?

 

This expression does it for you.

 

The Match expression:

(<li[^>]*?><a[^>]*?>)({[^<]*?</a>)

 

The Replace expression:

\1<img src="dbtech/vbnavtabs/images/whats_new_image/whats_new.png"  style="margin-bottom:.25em; vertical-align:middle;' . $image_padding . '" >\2

 

A preg_repace that takes the $subject string as input:

$result = preg_replace('%(<li[^>]*?><a[^>]*?>)(\{[^<]*?</a>)%m', '\1<img src="dbtech/vbnavtabs/images/whats_new_image/whats_new.png"  style="margin-bottom:.25em; vertical-align:middle;\' . $image_padding . \'" >\2', $subject);

 

Is this what you were looking for? Your code boxes were pretty full so I may have misunderstood.

Wishing you a fun day

Link to comment
https://forums.phpfreaks.com/topic/253355-preg_replace-help/#findComment-1299571
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.