This is my matching regex (just starting with matching before I move on to the preg_replace
Code: Select all
preg_match('#<a href="([^http://www\.domain\.com].*)">#', $text, $matches);Moderator: General Moderators
Code: Select all
preg_match('#<a href="([^http://www\.domain\.com].*)">#', $text, $matches);Everything between '[' and ']' (also called a character class, or character set) will match just a single character. So, this part of your expression:shiznatix wrote:As part of this RSS feed I am writing I want to turn all relative URLs to non-relative URLs but am of course having trouble (otherwise, why would I post)
This is my matching regex (just starting with matching before I move on to the preg_replaceWhat I want is if a link does not start with http://www.domain.com for it to return that in $matches but of course what it is doing now is if it contains any of those letters it won't return, I want it to be like "starts with" instead of "contains anywhere". How do I do this?Code: Select all
preg_match('#<a href="([^http://www\.domain\.com].*)">#', $text, $matches);
Code: Select all
<?php
$text = 'text <a href="http://www.domain.com/foo">foo</a>
text <a href="/foo2">foo2</a> more text to ignore
text <a href="http://www.domain.com/bar">bar</a>
text <a href="bar2">bar2</a> and this is the end.';
echo '<pre>';
echo $text;
echo '</pre>';
if(preg_match_all('@(?<=<a\shref=")(?!http://)[^"]+@', $text, $matches)) {
echo '<pre>';
print_r($matches);
echo '</pre>';
}
?>Code: Select all
$text = preg_replace('@(?<=<a\shref=")(?!http://)/?([^/][^"]+)@', 'http://www.domain.com/$1', $text);Good to hear it, and you're welcome.shiznatix wrote:yessir thats what i needed. super thanks