Q
添加字符
0
A
回答
1
echo "'" . str_replace(' ', "' '", 'dddd ggggb btbtgbgb gtrbr') . "'";
// returns 'dddd' 'ggggb' 'btbtgbgb' 'gtrbr'
0
$str = "dddd ggggb btbtgbgb gtrbr";
echo "'" . str_replace(' ', "' '", preg_replace('/\s\s+/', ' ', $str)) . "'";
//returns 'dddd' 'ggggb' 'btbtgbgb' 'gtrbr' and strips extra whitespace if ever your text file has extra whitespaces.
0
// load file into an array
$lines = file($textfile);
foreach ($lines as $key => $line) {
// add quotes and remove tailing newline
$lines[$key] = "'".rtrim($line, "\n")."'";
}
print_r($lines);
注意:這可能不會很好地擴展。
相關問題
- 1. 添加字符
- 2. 添加字符串逐字字符串
- 3. 添加字符串爲int /添加整數的字符串
- 4. 向字符串流添加字符
- 5. 將字符添加到字符串
- 6. Java將字符添加到字符串
- 7. 字符添加到字符串
- 8. 在C字符添加到字符串
- 9. 將字符串添加到字符串
- 10. 從字符串添加字符疊
- 11. Python - 將字符添加到字符串
- 12. 將字符添加到字符串vb.net
- 13. 將字符添加到字符串
- 14. 添加字符PostgreSQL的
- 15. PHP:不添加字符串
- 16. 添加字符到$ config [allowed_uri_chars]
- 17. 添加1到字符串
- 18. 添加「字符串SQL
- 19. 添加操作字符串
- 20. ArrayList不添加字符串
- 21. 添加字符串資源
- 22. jQuery添加href字符串
- 23. 如何添加字符串
- 24. 是GetByteCount(字符串)添加?
- 25. Android添加cp866字符集
- 26. 添加字符在句子
- 27. 如何添加字符
- 28. 添加字符和int
- 29. redshift添加轉義字符
- 30. NSRegularExpression添加轉義字符
更好的答案? –