Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Add acronyms to an html page
Old 11-28-2007, 12:12 PM Add acronyms to an html page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
I've been playing around, trying to add abbr's to an html page. Whilst the following was working fine...
PHP Code:
$buffer str_replace("UK""United Kingdom"$buffer); 
...it falls apart when the abbreviation is within an html tag like href.

I'm therefore assuming this needs to be done with a regex. Can anyone suggest how?

Thanks.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.

Last edited by fambi; 11-28-2007 at 12:30 PM..
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 11-28-2007, 12:29 PM Re: Add acronyms to an html page
Super Talker

Posts: 134
Trades: 0
there is a " missing after UK
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
Old 11-28-2007, 12:30 PM Re: Add acronyms to an html page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Thanks. That was a typo, but the real problem still exists.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 11-28-2007, 09:27 PM Re: Add acronyms to an html page
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
http://us.php.net/ereg_replace
http://us.php.net/preg_replace
I personally use ereg.
I'm not sure what you mean by if falls apart, do you mean you want it to cleanse the HTML tags, or do you want it to stay out of HTML tags?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-28-2007, 10:53 PM Re: Add acronyms to an html page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Basically, imagine the following...
PHP Code:
$buffer "<p>This is the UK.</p>";
$buffer str_replace("UK""<abbr title='United Kingdom'>UK</abbr>"$buffer);  
//Prints <p>This is the <abbr title='United Kingdom'>UK</abbr>.</p> 
That's fine.

But now imagine this...
PHP Code:
$buffer "<a href="X" title="UK Homepage">Link text</a>";
$buffer str_replace("UK""<abbr title='United Kingdom'>UK</abbr>"$buffer);  
//Prints <a  href="X" title="<abbr title='United Kingdom'>UK</abbr>" Homepge">Link Text</a> 
So rather than doing a replace on all text, the replace should exclude html tags.

(Note: Searching for a solution, I realised that asked about this before but couldn't get a solution).
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 11-29-2007, 12:31 PM Re: Add acronyms to an html page
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
OK the only thing I can think of is take an array of all characters and build an if/for loop where if the array[] character == '<' go into a for loop until you hit a '>'. Quite system intensive and I'm sure someone will come along with a way to improve on this, or who actually uses arrays and can give you the code for it. Pretty much you'd be looping through all the characters and I don't know arrays to tell you how it'd be done.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-29-2007, 01:01 PM Re: Add acronyms to an html page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Thanks for the suggestion, but that is very far from ideal.

Oh regexp hero, where are you?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Add acronyms to an html page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25503 seconds with 12 queries