たとえば、$url=' https://www.myurl.com/monkey-48-chicken-broccoli-ham.html ' という URL があります。パスを取得し、末尾を 2 つの変数に分割します。1 つは数字 (48) を含み、もう 1 つは数字の後のすべて (チキン-ブロッコリー-ハム) を含みます。
以下のコードから返された配列を個別の単語に分割することはできますが、問題は、数字の後にいくつの単語が続くかわからないことです。
私の質問は、パスを「数値」と「数値の後のすべて」に分割して、それらを変数として保存するにはどうすればよいですか? これが私がこれまでに持っているものです:
$url='https://www.myurl.com/monkey-48-chicken-broccoli-ham.html';
$parsedUrl = parse_url($url);
$path = parse_url($url, PHP_URL_PATH);
$parts = explode('/', $path);
$tag = end($parts);
$tag1 = str_replace("-", " ", $tag); //replace - with spaces
$tag2 = str_replace(".html", "", $tag1);//delete the ".html" off the end
$tag3 = str_replace("monkey", "", $tag2); //delete the "monkey" word.
ここで助けが必要です:
$number = ???;
$wordstring = ???;