Non sono bravo in espressioni Mi piacerebbe abbinare la stringa sotto di una stringa.
http://www.site.com/ * .js
preg_match("(http://www.site.com/).*(.js)",$html,$match);
So che questo codice non è giusto. * Rappresenta qualsiasi file con estensione .js. Qualcuno potrebbe guidarmi con l'espressione. Scusa se qualche duplicazione.
risposte:
1 per risposta № 1Devi usare delimitatori come "#", "@" o "/" nel modello:
$url = "http://www.site.com/javascript/test.js";
$preg_match = preg_match("#(http://www.site.com/)(.*)(.js)#", $url, $matches);
if($preg_match === 1)
{
var_dump($matches);
// displays :
// array
// 0 => string "http://www.site.com/javascript/test.js" (length=38)
// 1 => string "http://www.site.com/" (length=20)
// 2 => string "javascript/test" (length=15)
// 3 => string ".js" (length=3)
}
else
{
// doesn"t match
}