這是一個有點長切因爲我不熟悉與正則表達式,所以我已經使用字符串函數。試用於不同的場合,看它是否行之有效?
$str = '{"meta":{"code":200},"data":[{"created_time":"1358953338","text":"ciye koki sushi :))","from":{"username":"mayarahmanita","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_282786052_75sq_1357394407.jpg","id":"282786052","full_name":"Mayaa Rahmanita Hardianti"},"id":"375250258876255756"},{"created_time":"1358954810","text":"baguuus kan ada yg digoreng jg lho :-D","from":{"username":"realwahyuputra","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg","id":"180213154","full_name":""},"id":"375262607376994013"},{"created_time":"1358960360","text":"mau dong nyoba :3","from":{"username":"mayarahmanita","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_282786052_75sq_1357394407.jpg","id":"282786052","full_name":"Mayaa Rahmanita Hardianti"},"id":"375309164881202914"},{"created_time":"1358960656","text":"makanya jgn lama2 di balinya :-[","from":{"username":"realwahyuputra","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg","id":"180213154","full_name":""},"id":"375311649997934355"},{"created_time":"1388808291","text":"Sushi Homemade #title","from":{"username":"realwahyuputra","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg","id":"180213154","full_name":""},"id":"625691760184610726"},{"created_time":"1388808305","text":"Rp50.000 #price","from":{"username":"realwahyuputra","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg","id":"180213154","full_name":""},"id":"625691875997732786"}]}';
$substring = substr($str,0,strpos($str,'#title')); //returns from start of string till Sushi Homemade
$new2 = strrpos($substring,'"',-1); //searches backwards and returns position of first " found
$new3 = substr($substring,$new2+1,strlen($substring)); //extracts string from " till end of string
echo trim($new3); //trimming forward and trailing space and displaying the needed string value
以及如何從指定的關鍵字提取文本之間的json? – cutez7boyz
使用json解碼和解析 –