By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

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

P: n/a
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);
}
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/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.
Jul 17 '05 #2

P: n/a
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.
Jul 17 '05 #3

P: n/a
Thank you so much Pedro!
Jul 17 '05 #4

P: n/a
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.
Jul 17 '05 #5

P: n/a
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 :P
Now I'm so powerful that even my mom is afraid to come to my room ;)
Jul 17 '05 #6

P: n/a
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.
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.