Detecting a url using preg_match? without http:// in the string

后端 未结 5 1040
执念已碎
执念已碎 2020-11-30 08:12

I was wondering how I could check a string broken into an array against a preg_match to see if it started with www. I already have one that check for http://www.

         


        
5条回答
  •  一生所求
    2020-11-30 08:29

    You want something like:

    %^((https?://)|(www\.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i
    

    this is using the | to match either http:// or www at the beginning. I changed the delimiter to % to avoid clashing with the |

提交回复
热议问题