我有这个
echo "<div class='weather " . $cell->textContent ."'>";
当 textContent 只是像“sunny”这样的一个词时,这很好用。但是,如果当前天气是例如“部分多云”,我当然会应用两个类(.partially 和 .cloudy 而不是 .partially-cloudy。
如何确保 textContent 中包含两个(或更多)单词时,我用连字符替换所有空格?
这不起作用:
echo "<div class='weather " . substr_replace(" ", "-", $cell->textContent) ."'>";
谢谢你。