Add http:// prefix to URL when missing

前端 未结 10 1228
谎友^
谎友^ 2020-11-30 06:41

Hello I have a very simple code


    
Website
10条回答
  •  孤城傲影
    2020-11-30 07:18

    You could use strpos:

    // Trim trailing whitespace
    $aProfileInfo['Website'] = trim($aProfileInfo['Website']);
    
    // Test if the string begins with "http://"
    if (strpos($aProfileInfo['Website'], 'http://') !== 0) {
      $aProfileInfo['Website'] = 'http://' . $aProfileInfo['Website'];
    }
    

提交回复
热议问题