0

I have a php function which generates tags from string:

function generate_tags($text)
{
    $string = preg_replace('/[^\p{L}\p{N}\s]/u', ' ', $text);
    $string = preg_replace('/\s+/', ' ', $string);
    $string = mb_strtolower($string, 'UTF-8');
    $keywords = explode(' ', trim($string));
    foreach($keywords as $key => $value)
    {
        if((strlen($value)) < 1)
        {
            unset($keywords[$key]);
            continue;
        }
    }
    $result = array_unique($keywords);
    $result = array_values($result);
    return $result;
}

The string is: Ke$ha - We Are Who We Are (Cherry Cole Private Booty) Full Oficial Version

But it replaces $ symbol. How can I prevent $ symbol on my function?

Aykhan Amiraslanli
  • 593
  • 2
  • 8
  • 22
  • 2
    [This question](http://stackoverflow.com/q/767714/5620297) may be of use. Actually, [this question](http://stackoverflow.com/q/18993863/5620297) will probably be more helpful – Kaspar Lee Mar 19 '16 at 18:33

2 Answers2

1

Modify the first preg_replace to skip over $ as well:

$string = preg_replace('/[^\p{L}\p{N}\s$]/u', ' ', $text);
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
0

Modify the first preg_replace to skip over $ as well:$string = preg_replace('/[^\p{L}\p{N}\s$]/u', ' ', $text); you just have to press the tick underneath the voting buttons.