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

  php

Q(Question):

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);
}

A(Answer):

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.

A(Answer):

lecichy wrote:

And another simple question, maybe its the same answer.
whats the syntax of eregi_replace?

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

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 ">") # a literal ">"

([^<]*) # 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.

A(Answer):

Thank you so much Pedro!

A(Answer):

lecichy wrote:

Thank you so much Pedro!

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.

A(Answer):

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.

Enjoy what ?

Just kidding 😛
Now I’m so powerful that even my mom is afraid to come to my room 😉

A(Answer):

lecichy wrote:

Now I’m so powerful that even my mom is afraid to come to my room 😉

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.

LEAVE A COMMENT