TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-30-2009, 06:23 PM   #1 (permalink)
The Wanderer
 
unitechy's Avatar
 
Join Date: Mar 2008
Location: navi mumbai
Posts: 10
Thanks: 4
unitechy is on a distinguished road
Default ignore hyperlinked text

I have been working on some wp-plugin to practice php.
I have made a dictionary... which reads posts from wordpress post and the plugin converts difficult words stored in the a text file.
Now I don't want the plugin to read hyperlinked text. how do I achieve that? here is my code.

PHP Code:
if(stristr($the_content,$wordAndMeaning[0]) != false)
            {
                
$the_contentstr_replace($wordAndMeaning[0], "<acronym title=\"" $wordAndMeaning[1] . "\">" $wordAndMeaning[0] . "</acronym>"$the_content);
            } 
__________________
How to crash your pc??
Send a message via AIM to unitechy Send a message via MSN to unitechy Send a message via Yahoo to unitechy Send a message via Skype™ to unitechy
unitechy is offline  
Reply With Quote
Old 11-01-2009, 05:28 PM   #2 (permalink)
The Wanderer
 
unitechy's Avatar
 
Join Date: Mar 2008
Location: navi mumbai
Posts: 10
Thanks: 4
unitechy is on a distinguished road
Default

Can anyone please reply?
__________________
How to crash your pc??
Send a message via AIM to unitechy Send a message via MSN to unitechy Send a message via Yahoo to unitechy Send a message via Skype™ to unitechy
unitechy is offline  
Reply With Quote
Old 11-01-2009, 08:51 PM   #3 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 17
Thanks: 0
Rhinos is on a distinguished road
Default

You could use your function and then use a regular expression to remove all the <acronym> tags that appear inside <a> tags.

Here is a regular expression I have come up with. I have only tested it using a javascript regexp tester at http://www.regular-expressions.info/...ptexample.html

It should be the same for PHP though:

PHP Code:
$the_content preg_replace('~(<a.*>)<acronym.*>(.*)</acronym>(</a>)~i''$1$2$3'$the_content); 
Let me know how you get on.
Rhinos is offline  
Reply With Quote
The Following User Says Thank You to Rhinos For This Useful Post:
unitechy (11-02-2009)
Old 11-01-2009, 09:11 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Your regexp is far too greedy, if there's multiple occurences, you might find that it strips them all out and everything in between. Something like the following (untested) may work;

php Code:
$the_content = preg_replace('#(<a[^href]+href[^>]+>)<acronym[^>]+>([^<]+)</acronym></a>#', '$1$2</a>', $the_content);
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
unitechy (11-02-2009)
Old 11-01-2009, 09:54 PM   #5 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 17
Thanks: 0
Rhinos is on a distinguished road
Default

Your right. I've tried to work mine a little since when I tried yours on the javascript tester page it didn't work with the following information:

Regexp: (<a[^>]*>)?(<acronym[^>]*>(.*?)</acronym>)(</a>)?
Subject string: hey <a href="test"><acronym>yo</acronym> yo <acronym>bob</acronym></a> what's up? <a href="test">nothing</a>
Replacement text: $1$3$4

Code:
$the_content = preg_replace('~(<a[^>]*>)?(<acronym[^>]*>(.*?)</acronym>)(</a>)?~i', '$1$3$4', $the_content);
Let me know what you think.
Rhinos is offline  
Reply With Quote
The Following User Says Thank You to Rhinos For This Useful Post:
unitechy (11-02-2009)
Old 11-02-2009, 06:36 AM   #6 (permalink)
The Wanderer
 
unitechy's Avatar
 
Join Date: Mar 2008
Location: navi mumbai
Posts: 10
Thanks: 4
unitechy is on a distinguished road
Default

Thank you very much for the replies. I have used the following code now.
Code:
while(!preg_match(<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>,$the_content))
				{
				$the_content= str_replace($wordAndMeaning[0], "<acronym title=\"" . $wordAndMeaning[1] . "\">" . $wordAndMeaning[0] . "</acronym>", $the_content);
				}
__________________
How to crash your pc??
Send a message via AIM to unitechy Send a message via MSN to unitechy Send a message via Yahoo to unitechy Send a message via Skype™ to unitechy
unitechy is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
php/html form to echo text file contents Hustle Absolute Beginners 2 03-10-2009 07:14 AM
Text from Word-document Tanax General 13 02-06-2009 12:39 PM
Input-field with captured text falsely empties on click sidisinsane Javascript, AJAX, E4X 5 12-05-2008 12:12 AM
Need help editing/saving text files webosb Absolute Beginners 6 12-14-2007 06:43 PM
PDF Creation - Help! Sam Granger General 7 10-31-2007 11:32 AM


All times are GMT. The time now is 01:33 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design