开发者

php substr_replace space with hyphen?

i have this

echo "<div class='weather " . $cell->textContent ."'>";

this works fine when textContent is just one word like "sunny". However if the current weather is e.g. "partially cloudy" i get of course two classes applied (.partially and .cloudy instead of .partially-cloudy.

How can I make sure whenever there are two (or开发者_如何学C more) words contained in textContent I replace all spaces with a hyphen?

This does not work:

echo "<div class='weather " . substr_replace(" ", "-", $cell->textContent) ."'>";

Thank you.


Use str_replace:

echo "<div class='weather " . str_replace(" ", "-", $cell->textContent) ."'>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜