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) ."'>";
精彩评论