Help with Regex

Discussion in 'PHP' started by chaoscript, Dec 14, 2010.

  1. #1
    Hi,
    I have youtubetomp3 site, www.YoutubeToMP3.me,
    Now I have problem with videos that contain unusual chars, like
    ";,/
    PHP:
    etc.
    Here is the 2 functions that Saved the name from youtube:
            function ExtractSongTrackName($vidSrc, $srcType)
            {
                $name = '';
                $vidSrcTypes = $this->GetVidSrcTypes();
                if (in_array($srcType, $vidSrcTypes))
                {
                    $vidSrc = ($srcType == $vidSrcTypes[1]) ? file_get_contents($vidSrc) : $vidSrc;
                    if ($vidSrc !== false && eregi('eow-title',$vidSrc))
                    {
                        $name = end(explode('eow-title',$vidSrc));
                        $name = current(explode('">',$name));
                        $name = end(explode('title="',$name));
                    }
                }
                return $name;
            }        
    PHP:

           private function SetSongFileName($file_contents)
            {
                $vidSrcTypes = $this->GetVidSrcTypes();
                $trackName = $this->ExtractSongTrackName($file_contents, $vidSrcTypes[0]);
                return $this->_songFileName = (!empty($trackName)) ? self::_SONGFILEDIR . preg_replace('/_{2,}/','_',preg_replace('/ /','_',preg_replace('/^[A-Za-z0-9]+$/','',$trackName))) . '.mp3' : '';
            }
    PHP:

    Regards.
     
    chaoscript, Dec 14, 2010 IP
  2. mikecampbell

    mikecampbell Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    return $this->_songFileName = (!empty($trackName)) ? self::_SONGFILEDIR . preg_replace('/_{2,}/','_',preg_replace('/ /','_',preg_replace('/[^A-Za-z0-9 _]$/','',$trackName))) . '.mp3' : '';
    PHP:
     
    mikecampbell, Dec 14, 2010 IP
  3. chaoscript

    chaoscript Well-Known Member

    Messages:
    3,459
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    150
    #3
    Still don't work.

    Regards.
     
    chaoscript, Dec 14, 2010 IP
  4. mikecampbell

    mikecampbell Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oops, typo.

    return $this->_songFileName = (!empty($trackName)) ? self::_SONGFILEDIR . preg_replace('/_{2,}/','_',preg_replace('/ /','_',preg_replace('/[^A-Za-z0-9 _]/','',$trackName))) . '.mp3' : '';
    PHP:
    If this doesn't work, then give more detail. Do you get an error? Do you get a result you didn't expect?
     
    mikecampbell, Dec 14, 2010 IP
  5. chaoscript

    chaoscript Well-Known Member

    Messages:
    3,459
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    150
    #5
    Now it's work with unusual chars, but with Hebrew language, don't work.
    I need that it'll work both.

    Regards.
     
    chaoscript, Dec 15, 2010 IP