mirror of
https://github.com/standardebooks/web.git
synced 2025-07-12 01:22:23 -04:00
Fix iconv bug with apostrophes
This commit is contained in:
parent
c879dcab34
commit
5939195955
2 changed files with 6 additions and 4 deletions
|
@ -148,7 +148,7 @@ class Ebook{
|
|||
$this->Timestamp = new \DateTime((string)$xml->xpath('/package/metadata/dc:date')[0]);
|
||||
|
||||
// Get SE tags
|
||||
foreach($xml->xpath('/package/metadata/meta[@property="meta-auth"]') ?: [] as $tag){
|
||||
foreach($xml->xpath('/package/metadata/meta[@property="se:subject"]') ?: [] as $tag){
|
||||
$this->Tags[] = (string)$tag;
|
||||
}
|
||||
|
||||
|
@ -335,6 +335,7 @@ class Ebook{
|
|||
}
|
||||
|
||||
// Remove diacritics and non-alphanumeric characters
|
||||
$searchString = str_replace(['‘,', '’'], '', $searchString);
|
||||
$searchString = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', iconv('UTF-8', 'ASCII//TRANSLIT', $searchString) ?: '') ?? '');
|
||||
$query = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', iconv('UTF-8', 'ASCII//TRANSLIT', $query) ?: '') ?? '');
|
||||
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
<?
|
||||
class Formatter{
|
||||
public static function MakeUrlSafe(string $text): string{
|
||||
// Remove apostrophes
|
||||
// We have to do this first so iconv doesn't choke
|
||||
$text = str_replace(['\'', '‘,', '’'], '', $text);
|
||||
|
||||
// Remove accent characters
|
||||
$text = iconv('UTF-8', 'ASCII//TRANSLIT', $text) ?: '';
|
||||
|
||||
// Trim and convert to lowercase
|
||||
$text = mb_strtolower(trim($text));
|
||||
|
||||
// Remove apostrophes
|
||||
$text = preg_replace("/['’]/ius", '', $text) ?: '';
|
||||
|
||||
// Then convert any non-digit, non-letter character to a space
|
||||
$text = preg_replace('/[^0-9a-zA-Z]/ius', ' ', $text) ?: '';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue