简体   繁体   中英

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 eg "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 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.

使用str_replace

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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