I want to replace something like http://www.somesite.com/videos/video23.mp4 with something like <some_my_tag>http://www.somesite.com/videos/video23.mp4</some_my_tag>. How to do it in PHP?
views:
37answers:
4don't answer your own question, rather add a comment to it
                  krike
                   2010-08-24 20:51:15
                
                
                A: 
                
                
              preg_replace('#http://(.+?)\.mp4#i', '<tab>http://$1.mp4</tag>', $text)
                  joebert
                   2010-08-24 20:50:21
                
              
                +1 
                A: 
                
                
              
            like this:
$url = "http://www.somesite.com/videos/video23.mp4";
$output = preg_replace('/((?:http|https):\/\/[a-z0-9\/\?=_#&%~-]+(\.[a-z0-9\/\?=_#&%~-]+)+)|(www(\.[a-z0-9\/\?=_#&%~-]+){2,})/', '<some_my_tag>$1</some_my_tag>', $url);
The regex pattern will allow you to find any kind of url's
I answered a (more or less) similar questions here -> http://stackoverflow.com/questions/2738555/highlighting-search-results-in-php-mysql/2739238#2739238
                  krike
                   2010-08-24 20:50:50
                
              
                +3 
                A: 
                
                
              
            As you said that "Everything except .mp4" can change in the URL, then you can use this:
$NewStr = preg_replace('#http://(.+?)\.mp4#i', '<some_my_tag>http://$1.mp4</some_my_tag>', $Str);
                  shamittomar
                   2010-08-24 20:52:53