IT.COM

{PHP} Regular expressions trouble

Spaceship Spaceship
Watch

Alex.

Account Closed
Impact
5
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([^.]+)>','[b]',$data);
But that gives me:
Fixed a bug that disconnected some....

Instead of:
Code:
[/b]Bug Fixes[/b]<ul class="bullet-list"><li>Fixed a bug that disconnected some....

All I need is an expression that will grab any character.

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
Bug Fixes
  • 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:

    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:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
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:
<?php
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">');
?>
 
0
•••
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.
Any ideas? :-/

edit- also, whats the pattern for any number / type of character?
 
Last edited:
0
•••
BUMP
Willing to give 20NP for answer to NEW problem in first post.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back