使用PHP删除字符串的字符

问题描述:

Im trying to show local shops in a area the user types in a post code it then grabs shops from the database and displays them so i need it so when a user types in a post code like so

mp1234

it will just keep the mp1 in my database there is a covered table were the stores add post codes to show they cover this area so they add the start of each post code like so mp1 to say they cover that area. The user will be entering the full post code so just need the first 3 char.

Thank you

我试图在用户在邮政编码中键入的区域中显示本地商店,然后从数据库中抓取商店 显示它们所以我需要它,所以当用户输入一个像这样的邮政编码 p>

mp1234 p>

它只会将mp1保存在我的数据库中 是一个有盖的表是商店添加邮政编码,以显示他们覆盖这个区域,所以他们添加每个邮政编码的开头,如mp1,说他们覆盖该区域。 用户将输入完整的邮政编码,因此只需要前3个字符。 p>

谢谢 p> div>

You should use the substr built-in PHP function: http://php.net/manual/en/function.substr.php

This function will allow you to get substrings from a given string. For example:

$postcode = 'GU14LG';
$region = substr($postcode, 0, 3); // This is now GU1