There is an array, inside it links:

$array = array( "<a href='https://site.ru/catalog/a/texas.html'>Texas</a>", "<a href='https://site.ru/catalog/b/idaho.html'>Idaho</a>", "<a href='https://site.ru/catalog/b/washington.html'>Washington</a>", "<a href='https://site.ru/catalog/b/seattle.html'>Seatle</a>", ); 

Simply using sort () naturally does not work, since it sorts the entire link by text, and not by its name.

1 answer 1

 $array = array( "<a href='https://site.ru/catalog/a/texas.html'>Texas</a>", "<a href='https://site.ru/catalog/b/idaho.html'>Idaho</a>", "<a href='https://site.ru/catalog/b/washington.html'>Washington</a>", "<a href='https://site.ru/catalog/b/seattle.html'>Seatle</a>", ); 

It is possible so:

 usort($array, function($a, $b) { $a = preg_replace('/<a[^>]+>([^<]+)<\/a>/i', '$1', $a); $b = preg_replace('/<a[^>]+>([^<]+)<\/a>/i', '$1', $b); return $a > $b; }); 

Similarly, without regulars:

 usort($array, function($a, $b) { $a = strip_tags($a); $b = strip_tags($b); return $a > $b; }); 

Conclusion:

 var_dump($array); 

 array(4) { [0]=> string(56) "<a href='https://site.ru/catalog/b/idaho.html'>Idaho</a>" [1]=> string(59) "<a href='https://site.ru/catalog/b/seattle.html'>Seatle</a>" [2]=> string(56) "<a href='https://site.ru/catalog/a/texas.html'>Texas</a>" [3]=> string(66) "<a href='https://site.ru/catalog/b/washington.html'>Washington</a>" }