PHP实用代码片段(四)
1. 删除文件夹内容 function Delete( $path ) { if ( is_dir ( $path ) === true ) { $files = array_diff ( scandir ( $path ), array ('.', '..' )); foreach ( $files as $file ) { Delete( realpath ( $path ) . '/' . $file ); } return rmdir ( $path ); } else if ( is_file ( $path ) === true ) { return unlink ( $path ); } return false ; } 语法: <? php $path = "images/" ; Delete( $path ); // This will delete images folder along with its contents. ?> 2. 搜索和高亮字符串中的关键字 function highlighter_text( $text , $words ) { $split_words = explode ( " " , $words ); foreach ( $split_words as $word ) { $color = "#4285F4" ; $text =