我正在做一個鏈接和文本服務,但我有一個問題,那就是:只有1個輸入文本形式,用戶可以貼上這樣的事情: http:// asdf .com
- 這將登記爲紐帶,或者因爲HTTP的「asdf http:// test .com
」://,它會註冊爲網址,或 asdf
- 這將註冊爲一個字符串,因爲它不包含HTTP://確定URL或字符串PHP
,但我的當用戶寫入如下內容時會出現問題: asdf http://asdf.com
,它在我當前的程序中輸出「url」值。我已經經歷過了大約一個小時,現在,我已經有了一個代碼3位(!他們都被評論在同一文件中,所以請原諒我,如果他們放棄錯誤)
<?
$str = $_POST['paste'];
if(stristr($str, "http://")) {
$type = "url";
}
if(stristr($str, "https://")) {
$type = "url";
}
if($type!="url") {
$type = "string";
}
?>
下一頁:
<?
$type = "url";
if($type=="url"){
$t = substr($str, 8);
if(stristr($t, "https://")==$t){
$type = "url";}
if(stristr($t, "https://")==$t){
$type = "url";}
if(stristr($t, "http://")!=$t){
$type = "string";}
if(stristr($t, "https://")!=$t){
$type = "string";}
}
echo $type;
?>
下一頁:
<?
$url = "hasttp://cake.com";
if(stristr($url, "http://")=="") {
$type = "string"; } else {
$type = "url";
$sus = 1;}
if(stristr($url, "http://")==$url) {
$type = "url"; }
if($sus==1) {
$r = substr($url, 7);
if(stristr($r,"http://")!="http://") {
$type = "url"; }
if($r=="") {
$type = "string";
}
}
echo $type;
?>
我不知道我怎麼會去一個字符串進行分類,如「asdf http://asdf.com
」作爲一個字符串,而分類「asdf
」作爲一個字符串,並分類「http://asdf.com
'作爲網址..我還沒有嘗試過的另一個想法是strpos,但這就是我現在正在處理的內容。
任何想法?
非常感謝! :)
這個問題的某些部分由於某種原因而被切斷,致歉!
你基本上是問這些:http://stackoverflow.com/search?q=linkify+php?對? – Gordon