简体   繁体   English

提取标签的最佳方法是什么

[英]What is the best approach to extract a tag

I have this elements where I need to extract this {{search_tag}} and replace by a value 我在需要提取此{{search_tag}}并将其替换为值的地方有此元素

https://www.toto.com/search/10/{{search_tag}}.html#_his_

I tried this but I don't if it's the good way, does'nt work. 我试过了,但如果这样做是好的,那我就不起作用。

$words = explode('{{search_tag}} ',$website_url[$n]);
$exists_at = array_search($seach,$words);
if ($exists_at){
  echo "Found at ".$exists_at." key in the \$word array";
}

You can use str_replace 您可以使用str_replace

$str = 'https://www.toto.com/search/10/{{search_tag}}.html#_his_';
$val = 'NEW_VALUE';
$new_str = str_replace("{{search_tag}}", $val, $str);
//outputs: https://www.toto.com/search/10/NEW_VALUE.html#_his_

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM