NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page {PHP} Regular expressions trouble

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-27-2007, 12:19 PM THREAD STARTER               #1 (permalink)
Account Closed
 
Alex.'s Avatar
Join Date: Nov 2006
Location: Uk
Posts: 601
Alex. is on a distinguished road
 


Ethan Allen Fund Third World Education

Help! {PHP} Regular expressions trouble


BUMP WILL GIVE 20NP FOR QUICK ANSWER,
Can anyone tell me what the POSIX expression for any character is?
I'm trying
Code:
$data = ereg_replace('<b([^.]+)>','',$data);

But that gives me:
Quote:
Fixed a bug that disconnected some....

Instead of:
Code:
 
Code:
Bug Fixes
Code:
<ul class="bullet-list"><li>Fixed a bug that disconnected some....
All I need is an expression that will grab any character.
????: NamePros.com http://www.namepros.com/programming/332604-php-regular-expressions-trouble.html

So I could ask it to parse
Code:
<b class="subhead">Bug Fixes[/b]<ul class="bullet-list"><li>Fixed a bug that di
into
Quote:
Bug Fixes[list][*]Fixed a bug that di
Thanks

Alex



Old post:

Hi,
I'm trying to make something that will parse html to bbcode.
This is my test code atm:
Code:
<?php
function myparse($data){
$data = htmlspecialchars_decode($data);
$data = eregi_replace('<a href="(([[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]))">','[url=\\0]',$data);
$data = htmlspecialchars($data);
return $data;

}
echo myparse('<a href="http://us.rd.yahoo.com/dailynews/rss/movies/*http://news.yahoo.com/s/ap/20070527/ap_en_mo/france_cannes_awards">');
?>
Now this just prints
Code:
[url=<a href="http://us.rd.yahoo.com/dailynews/rss/movies/*http://news.yahoo.com/s/ap/20070527/ap_en_mo/france_cannes_awards">]
I'd like it to print:
????: NamePros.com http://www.namepros.com/showthread.php?t=332604

Code:
[url=http://us.rd.yahoo.com/dailynews/rss/movies/*http://news.yahoo.com/s/ap/20070527/ap_en_mo/france_cannes_awards]
Help is appreciated
Thanks
Alex
Last edited by manofgames; 05-31-2007 at 02:27 PM.
Alex. is offline  
Old 05-27-2007, 04:02 PM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
You had a mistake in that the result within the brackets was 2nd in the array so had an index of 1 (arrays are zero based). Also I notice you had the main part of the regular expression in 2 sets of brackets which made no difference to the outcome so I removed 1 set.

PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=332604
function myparse($data){
$data htmlspecialchars_decode($data);
$data eregi_replace('<a href="([[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/])">','[url=\\1]',$data);
$data htmlspecialchars($data);
return 
$data;

}
echo 
myparse('<a href="http://us.rd.yahoo.com/dailynews/rss/movies/*http://news.yahoo.com/s/ap/20070527/ap_en_mo/france_cannes_awards">');
?>
Peter is offline  
Old 05-27-2007, 04:36 PM THREAD STARTER               #3 (permalink)
Account Closed
 
Alex.'s Avatar
Join Date: Nov 2006
Location: Uk
Posts: 601
Alex. is on a distinguished road
 


Ethan Allen Fund Third World Education
Thanks Pete,
I would give you rep but it doesn't like me giving you it

I'm having another little problem as well now with an image function:
Code:
$data = eregi_replace('<img src="(([[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]))"([^\.]+)>','[img]\\1[/img]',$data);
Nothing is changing with the output.
????: NamePros.com http://www.namepros.com/showthread.php?t=332604
Any ideas?

edit- also, whats the pattern for any number / type of character?
Last edited by manofgames; 05-27-2007 at 05:51 PM.
Alex. is offline  
Old 05-31-2007, 02:28 PM THREAD STARTER               #4 (permalink)
Account Closed
 
Alex.'s Avatar
Join Date: Nov 2006
Location: Uk
Posts: 601
Alex. is on a distinguished road
 


Ethan Allen Fund Third World Education
BUMP
Willing to give 20NP for answer to NEW problem in first post.
Alex. is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:58 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger