SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
IBM developerWorks
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old September 14th, 2002, 03:02 PM
Inferno Inferno is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 29 Inferno User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 54 sec
Reputation Power: 0
Send a message via Yahoo to Inferno
replace text within a string?

Hello:

Could someone please tell me if it is possible to replace "www.mysite.com" with something like "***" or whatever in a string?

example:

$string = "Hello all, please visit my site at www.mysite.com!n";

so it says:

$string = "Hello all, please visit my site at ***!n";


Any ideas?

Thanks in advance!

Reply With Quote
  #2  
Old September 14th, 2002, 04:24 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: replace text within a string?

I am thinking you are wanting to replace any url? in that case use something like:

$string = eregi_replace( "(http|https|ftp)://([[:alnum:]+-=%&:_.~?]+[#[:alnum:]+]*)",
"***",
$string);

Reply With Quote
  #3  
Old September 14th, 2002, 04:40 PM
Inferno Inferno is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 29 Inferno User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 54 sec
Reputation Power: 0
Send a message via Yahoo to Inferno
RE: replace text within a string?

Hi Matt:

Thanks for the reply!

That works great if they have the "http://" but what if the went like "www.mysite.com" or even "mysite.com"?

Is there anyway to get around that?

Reply With Quote
  #4  
Old September 15th, 2002, 11:25 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: replace text within a string?

u can detect www.somesite.tld by adding www in first part of regex like
php Code:
Original - php Code
  1.  
  2. $string = eregi_replace( "(http://|https://|ftp://|www.)([[:alnum:]+-=%&:_.~?]+[#[:alnum:]+]*)",
  3. "***", $string);


but i don't think that u can detect somesite.com

or u can, but it would also detect numbers of 3.14 or other stuff...


and matt, a pro like u should use pcre, not ereg ;)

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > replace text within a string?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway