Answer the question
In order to leave comments, you need to log in
How to do a universal link search using preg_match_all?
How to find all links that meet the following requirements using one query:
located on the domains mydomain1.com, site.ru, superdomen.org.ru ... the number of domains can be added. Also, the link can be
<a href="_сылка_">...</a>
<a href="_сылка_">...</a>
[url]_сылка_[/url]
[url=_сылка_]...[/URL]
Answer the question
In order to leave comments, you need to log in
Hello.
It can be like this.
Example
This part is repeated three times
To add another domain, simply use this entry.
We want to add google.com, then to this part mydomain1\.com.*|site.ru.*|superdomen\.org\.ru.* we add through the symbol | this entry: google.com.* And we get:
mydomain1\.com.*|site.ru.*|superdomen\.org\.ru.* |google.com.*
This is not the best option, if you think carefully, you can think of a better volume), but this is one of the easiest ways).
Well, I was able to come up with something like this:
$string = "some text
[url]http://dvz.local/index/index/regionId/28[/url]
<a href=\"http://stuff.ru/roadmap_page.php\">wetrwetwert</a> [url=https://192.168.3.192/roadmap_page.php]qqqqqqqqq[/url]
[URL]http://www.192.168.3.192/roadmap_page.php#qwe[/URL]";
preg_match_all('#(http|https)://([^\s]*)(192.168.3.192|stuff.ru)([^\s]*)#', $string, $matches);
var_dump($matches);
array(3) {
[0]=>
string(49) "http://stuff.ru/roadmap_page.php">wetrwetwert</a>"
[1]=>
string(54) "https://192.168.3.192/roadmap_page.php]qqqqqqqqq[/url]"
[2]=>
string(51) "http://www.192.168.3.192/roadmap_page.php#qwe[/URL]"
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question