さまざまな長さのさまざまな種類の文字列があります
例:
/my-big-property/Residential/Sections-for-sale
/my-big-property/Residential/for-sale
削除したいのですが、機能しないようです/my-big-property/
ので、他にどのようなオプションがありますか?substr
substr
うまくいかないことでさらに説明できますか?これは非常に単純な問題のようです。
<?php
$a = "/my-big-property/Residential/Sections-for-sale";
$b = substr($a, 17);
echo $b;
/
1番目と2番目の間の最初の文字列/
が可変である場合、次のような正規表現で十分です。
<?php
$a = "/my-big-property/Residential/Sections-for-sale";
preg_match("/\/\S+?\/(.*)/", $a, $matches);
print_r($matches);
これにより、次のように出力されます。
Array
(
[0] => /my-big-property/Residential/Sections-for-sale
[1] => Residential/Sections-for-sale
)
<?php
$a = "/my-big-property/Residential/Sections-for-sale";
$temp = explode('/my-big-property/',$a);
$temp_ans = $temp[1];
echo $temp_ans;
?>
2つの配列があり、1つは空白になり、もう1つは目的の値になります。
substrは正常に機能していますが、正しく使用されていません。手続きではなく機能です。元の文字列は変更されませんが、新しいサブ文字列が返されます。
正しい提案されたすべての解決策の上で、あなたは単に以下を使うことができます:
$string="/my-big-property/Residential/Sections-for-sale";
$string = str_replace("/my-big-property/", "", $string);