Connecting Tech Pros Worldwide Forums | Help | Site Map

=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'

lecichy
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello.


Well, I found this piece of code on php.net. Thats fine but where can i find
explanation for all these ("|\')?([^ "\']*)("|\')?.*>([^<]*)' syntax so that
I can construct my own rules for all kind of eregi preg and oter match
functions ?



Transform HTML links into plain-text "links" with the URL visible

function AHREF2text($string) {
return eregi_replace('<A .*HREF=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>',
'[\\4] (link: \\2)', $string);
}



lecichy
Guest
 
Posts: n/a
#2: Jul 17 '05

re: =("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'


And another simple question, maybe its the same answer.
whats the syntax of eregi_replace if I want to match ( remove in this
case ) few strings, not one:
eregi_replace (("stringone" && "stringtwo"), "", $source)
Or it just requires whole eregi expression each time ?
This ofcourse doesn't work but hope you know what I mean.


Pedro
Guest
 
Posts: n/a
#3: Jul 17 '05

re: =("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'


lecichy wrote:[color=blue]
>And another simple question, maybe its the same answer.
>whats the syntax of eregi_replace?[/color]

You better switch to preg_ functions. They're faster and more powerful
than ereg*
[color=blue]
>if I want to match ( remove in this case ) few strings, not one:
>eregi_replace (("stringone" && "stringtwo"), "", $source)[/color]

Try
<?php
$destin = preg_replace('/string(?:one|two)/i', '', $source)
?>


/string(?:one|two)/i -- means:

/ # start of regex
string # match "string literally"
(?: # start a group but don't grab (no need for that)
one # literal "one"
| # OR
two # literal "two"
) # end group
/i # end regex, but match without regard to case


see the preg_ function at
http://pt.php.net/manual/en/ref.pcre.php

Also try regex-coach from http://weitz.de/regex-coach/



using the PCRE_EXTENDED modifier (x) you can put the regex and
the comments in the source file

<?php
function AHREF2text($string) {
return preg_replace(
'@ # start of regex
<a[ ] # literal "<a " (notice the space)
[^<]* # any number of (any characters EXCEPT "<")
href= # literal "href="
("|\')? # optional double OR single quote (grabbed)
([^"\']*) # any number of (anything BUT double
## OR single quote) (grabbed)
("|\')? # optional double OR single quote (grabbed)
[^>]* # any number of (any characters EXCEPT ">")[color=blue]
> # a literal ">"[/color]
([^<]*) # any number of anything BUT "<" (grabbed)
</a> # literal "</a>"
@ix', # end regex, caseless and extended

'[\\4] (link: \\2)', $string);
}

// =============================

$x = 'At <a href="http://mysite.example.com/">my site</a> there
are many <a href="http://examples.example.com/">examples</a> :)';

echo $x, '<hr />', htmlentities($x), '<hr />', AHREF2text($x);
?>


--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
lecichy
Guest
 
Posts: n/a
#4: Jul 17 '05

re: =("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'


Thank you so much Pedro!


Pedro
Guest
 
Posts: n/a
#5: Jul 17 '05

re: =("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'


lecichy wrote:[color=blue]
> Thank you so much Pedro!
>[/color]

You're welcome lecichy.
Hope you enjoy regex's and the power they give you.

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
lecichy
Guest
 
Posts: n/a
#6: Jul 17 '05

re: =("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'


[color=blue]
> You're welcome lecichy.
> Hope you enjoy regex's and the power they give you.
>
> --
> I have a spam filter working.
> To mail me include "urkxvq" (with or without the quotes)
> in the subject line, or your mail will be ruthlessly discarded.[/color]

Enjoy what ?

Just kidding :P
Now I'm so powerful that even my mom is afraid to come to my room ;)


Pedro
Guest
 
Posts: n/a
#7: Jul 17 '05

re: =("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'


lecichy wrote:[color=blue]
> Now I'm so powerful that even my mom is afraid to come to my room ;)[/color]

Moms have more power than all the regex gurus put together!

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Closed Thread