php - replace both http and http: from url -


tried this,  $url = preg_replace('!(http|http:|ftp|scp)(s)?:\/\/[a-za-z0-9.=?&-_/]+!', "<a style=text-decoration:underline;color:blue href=\"\\0\" target='_blank' >\\0</a>",$feed->feed_text)): 

i want replace both http , http: url. tried above 1 replacing http , not http:.but if tried 1 of in regex working.if use both in expression not replacing http:

please see embeded script using,

1.<iframe frameborder="0" scrolling="no" id="chat_embed" src="http://twitch.tv/chat/embed?channel=athenelive&popout_chat=true" height="500" width="350"></iframe> ->having http:(need remove)

2.<iframe width="560" height="315" src="//www.youtube.com/embed/jxhojzlrxag" frameborder="0" allowfullscreen></iframe> ->if use http: alone in regex youtube embedded script not taken youtube url. both compatible purpose used http|http:.

update:

i need remove http: 1st frame given above.

should line

<iframe frameborder="0" scrolling="no" id="chat_embed" src="//twitch.tv/chat/embed?channel=athenelive&popout_chat=true" height="500" width="350"></iframe> 

it doesn't work http: because put colon after capturing group:

(http|http:|ftp|scp)(s)?:           ^             ^ 

to solve problem, remove http: capturing group (that useless):

(http|ftp|scp)(s)?: 

i think looking that:

$url = preg_replace('~\bhttps?:~', '', $url); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -