PHP string comparison won't match seemingly identical string

后端 未结 3 1520
梦毁少年i
梦毁少年i 2021-01-16 01:25

I am scraping the DOM of a static site with PHP and pulling out specific bit\'s of data so I can put stuff into a database.

For this example I am storing the inner H

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-16 02:17

    Solution is to use a regex like this

        function clean($string) {
    $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
    return preg_replace('/[^A-Za-z0-9\-\;\,\?\*\%\@\$\!\(\)\#\=\&]/', '', $string); // Removes special chars
    }
    

    Adapt it to the special char you need or not add the one you want to keep catching like this \# or esle \=

提交回复
热议问题