0
$text='some text and text http://soundcloud.com/disclosuremusic/whats-in-your-head some other text http://soundcloud.com/bad-panda-records/indian-wells-04 and again text blabla'; 

$text = preg_replace('#(?:https?://).soundcloud\.com/([\-a-z0-9_]+/[\-a-z0-9_]+)#siU','<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=$1&amp;g=bb"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=$1&amp;g=bb" type="application/x-shockwave-flash" width="100%"></embed></object> <a href="$1">$1</a>', $text);      

テキストからサウンドクラウドリンクを事前に置き換えようとしていますが、運が悪いようです。ありがとう

4

3 に答える 3

1

The "." before "soundcloud\.com" is failing the match

'%(?:https?://)(?:www\.)?soundcloud\.com/([\-a-z0-9_]+/[\-a-z0-9_]+)%im'

Do you need to account for www. at all?

于 2012-05-14T22:43:02.407 に答える
0

This will do it:

$text = preg_replace('/((http?:\/\/)soundcloud\.com\/([\-a-z0-9_]+/[\-a-z0-9_]+))/i','<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=$1&amp;g=bb"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=$1&amp;g=bb" type="application/x-shockwave-flash" width="100%"></embed></object> <a href="$1">$1</a>', $text);      

You had an extra dot before "soundcloud" and you were not properly escaping.

于 2012-05-14T22:52:43.970 に答える
0
$text='some text and text http://soundcloud.com/qcntoz some other text http://soundcloud.com/qcntoz and again text blabla'; 

$text = preg_replace('#(?:https?://).soundcloud\.com/([\-a-z0-9_]+/[\-a-z0-9_]+)#siU','<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=$1&amp;g=bb"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=$1&amp;g=bb" type="application/x-shockwave-flash" width="100%"> </embed></object> <a href="$1">$1</a>', $text);
于 2012-12-10T23:49:39.103 に答える