0
local szMsg = string.format("    歡迎來到非常劍俠有獎問答,您隻需交納%s就可以參加本次有獎答題,隻要您能回答正確<color=yellow>%s個<color>關於劍俠世界的小問題,就會獲得%s,如果中途答錯或者自己選擇退出,不僅沒有獎勵,您交納的%s也不會退還。怎麼樣,要參加嗎?", szNeedMoney, self.tbGroup[nGroupId].nQuestionMax, szAwardMsg, szNeedMoney);
local tbOpt =

I want to extract the data between the " " from my file using PHP.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MIF
  • 39
  • 6

2 Answers2

1

$string = ' local szMsg = string.format("歡迎來到非常劍俠有獎問答,您隻需交納%s就可以參加本次有獎答題,隻要您能回答正確%s個關於劍俠世界的小問題,就會獲得%s,如果中途答錯或者自己選擇退出,不僅沒有獎勵,您交納的%s也不會退還。怎麼樣,要參加嗎?", szNeedMoney, self.tbGroup[nGroupId].nQuestionMax, szAwardMsg, szNeedMoney); local tbOpt =" '; preg_match('/"([^"]+)"/', $string, $out); $output = str_replace('"', "", $out[0]); echo $output;

This will output:

歡迎來到非常劍俠有獎問答,您隻需交納%s就可以參加本次有獎答題,隻要您能回答正確<color=yellow>%s個<color>關於劍俠世界的小問題,就會獲得%s,如果中途答錯或者自己選擇退出,不僅沒有獎勵,您交納的%s也不會退還。怎麼樣,要參加嗎?

because it's inside the double quotes in $string;

Put your data as $string and you're done!

David
  • 3,831
  • 2
  • 28
  • 38
  • Hello david. Can i ask if i want preg_match_all in a file with this code : http://comicvn.net/ex.txt – MIF Jul 25 '12 at 21:17
  • You need to use `file_get_contents();` if it's a remote file. – David Jul 25 '12 at 21:18
  • If you have a really long file like that, you can use the $out array to get all the instances of the quotes. Or, you can use something like this to search for the line first: http://stackoverflow.com/a/2794073/1415625 – David Jul 25 '12 at 21:20
  • Look at comment with the link in it. It will search by line and then you can perform the regex on it – David Jul 25 '12 at 21:22
1

Give this a try

preg_match('/"(.+)"/',$string,$matches); // puts text into $matches[1]
Tim S
  • 5,023
  • 1
  • 34
  • 34