![]() |
|
Hoi mensen, ik heb de volgende code geschreven om de url in een meta redirect tag te kunnen wijzigen:
Code:
// URL met http:// converteren $line = eregi_replace("(http-equiv=[\"']?refresh[\"']?.*content=[\"']?.*)( url=http://)(.*[\"' ]{1}.*)", "\\1\\2preaper.homelinux.com/proxy/surf.php?url=http://\\3", $line); // URL zonder http:// converteren $line = eregi_replace("(http-equiv=[\"']?refresh[\"']?.*content=[\"']?.*)( url=)(http://){0}(.*[\"]{1}.*)", "\\1\\2http://preaper.homelinux.com/proxy/surf.php?url=http://".eregi("([/]?.*)$",$url)."\\4", $line); echo $line; Als je nog anderen op of aanmerkingen hebt aan mijn regex, zijn die ook welkom ![]() ![]()
__________________
█████████████████████99%
|
Advertentie | |
|
![]() |
|
![]() |
1. ik zou met Perl RegExps werken
2. zoekwerk op php.net: http://nl3.php.net/manual/en/ref.regex.php comment van regex at dan42 dot cjb dot net: It's easy to exclude characters but excluding words with a regular expression is a bit more tricky. For parentheses there is no equivalent to the ^ for brackets. The only way I've found to exclude a string is to proceed by inverse logic: accept all the words that do NOT correspond to the string. So if you want to accept all strings except those _begining_ with "abc", you'd have to accept any string that matches one of the following: ^(ab[^c]) ^(a[^b]c) ^(a[^b][^c]) ^([^a]bc) ^([^a]b[^c]) ^([^a][^b]c) ^([^a][^b][^c]) which, put together, gives the regex ^(ab[^c]|a[^b]c|a[^b][^c]|[^a]bc|[^a]b[^c]|[^a][^b]c|[^a][^b][^c]) Note that this won't work to detect the word "abc" anywhere in a string. You need to have some way of anchoring the inverse word match like: ^(a[^b]|[^a]b|[^a][^b]) ;"ab" not at begining of line or: (a[^b]|[^a]b|[^a][^b])& ;"ab" not at end of line or: 123(a[^b]|[^a]b|[^a][^b]) ;"ab" not after "123" I don't know why "(abc){0,0}" is an invalid synthax. It would've made all this much simpler.
__________________
Ooit. Dan.
|
![]() |
|||
Mja dat is dus de omweg
![]() Perl ben ik ook mee bezig, maar ik vind PHP toch net iets handiger ![]() btw: Als ik "url=(?!http://)" probeer(wat dus ook zou moeten werken...), geeft ie weer opeens een compile error :-/. Citaat:
Citaat:
__________________
█████████████████████99%
|
![]() |
||
![]() |
Citaat:
__________________
Ooit. Dan.
|
![]() |
|
$line = preg_replace("/ url=http:\/\/(\"|'| ||)(.*)(>|\"|')/i","url=/proxy/surf.php?url=http://$1hond$2", $line);
Hierbij werkt het wel, maar het doet absoluut niet wat ik wil.... Ik wil dat hij zoekt naar een: "url=http://", daarachter mag " of '. Vervolgens komt er een url (deze moet dus vervangen worden), en daarachter moet een ", ' of > staan.
__________________
█████████████████████99%
|
![]() |
||
![]() |
Citaat:
__________________
Ooit. Dan.
|
![]() |
|
|