2 回答

TA貢獻2039條經驗 獲得超8個贊
如果它是字符串中的最后一個鍵/值對,則可以使用 explode 獲取哈希值,方法如下...
在線 PHP 編輯器:
https://3v4l.org/kUrJs
$html = '<input type="hidden" name="payFormParams" id="payFormParams" value="payment_type=PaymentForm&merchant_id=117589463&trnType=P&errorPage=%2Fscripts%2Fpayment%2Fpayment%2Easp&approvedPage=&declinedPage=&epe_client_found=false&trnLanguage=eng&shipping_method=&ref1=&ref2=&ref3=&ref4=&ref5=&shippingMethod=&deliveryEstimate=&ordTax1Price=&ordTax2Price=&ordItemPrice=0&ordShippingPrice=0&trnOrderNumber=51029&trnAmount=5%2E00&ordName=Surreal+View&ordEmailAddress=xx%40gmail%2Ecom&ordPhoneNumber=2039581030&ordAddress1=3501+Jack+Northrop+Ave&ordCity=Hawthorne&ordProvince=CA&ordPostalCode=90250&ordCountry=US&paymentMethod=CC&trnCardOwner=Suyash&trnCardCvd=xxx&cavBirthMonth=&cavBirthDay=&cavBirthYear=&cavSin=&paymentAction=&trnCardNumber=xxxxxxxxx0412300&trnExpMonth=xx&trnExpYear=xx&aDFinancingType=&aDPlanNumber=&aDGracePeriod=&aDTerm=&hashValue=6a1562f5c4901522ab6926a4caf9f278">';
//Explode the input tag as a string at the `=` operators.
$ex = explode('=', $html);
// now use the count of the exploded array as a reference and subtract the keys by one to get the value of the hash.
$target = $ex[count($ex) - 1];
// This leaves you with a value that has the hash followed by a double quote and the closing tag for the input, explode again using the double quote
$hash = explode('"', $target);
// This leaves the hash and the symbols in our array, use the first key of 0 to get the value of the hash as you want it.
$targetHash = $hash[0];
退貨:
6a1562f5c4901522ab6926a4caf9f278
如果您不確定散列在字符串中的位置,您可以使用 explode 方法并搜索 的鍵hash,知道 NEXT 值將是實際的散列......所以它看起來像下面這樣......
一旦按 展開字符串,您就有了要搜索的=值,您知道展開后的數組中的下一個值將是實際的哈希值。&hashValue所以我們運行一個 foreach 并尋找那個值,然后找到keyturned的鍵value,我們用它來搜索散列,即key + 1。這將為我們提供帶雙引號的散列,引號展開這些散列并獲取散列。
$html = '<input type="hidden" name="payFormParams" id="payFormParams" value="payment_type=PaymentForm&merchant_id=117589463&trnType=P&errorPage=%2Fscripts%2Fpayment%2Fpayment%2Easp&approvedPage=&declinedPage=&epe_client_found=false&trnLanguage=eng&shipping_method=&ref1=&ref2=&ref3=&ref4=&ref5=&shippingMethod=&deliveryEstimate=&ordTax1Price=&ordTax2Price=&ordItemPrice=0&ordShippingPrice=0&trnOrderNumber=51029&trnAmount=5%2E00&ordName=Surreal+View&ordEmailAddress=xx%40gmail%2Ecom&ordPhoneNumber=2039581030&ordAddress1=3501+Jack+Northrop+Ave&ordCity=Hawthorne&ordProvince=CA&ordPostalCode=90250&ordCountry=US&paymentMethod=CC&trnCardOwner=Suyash&trnCardCvd=xxx&cavBirthMonth=&cavBirthDay=&cavBirthYear=&cavSin=&paymentAction=&hashValue=6a1562f5c4901522ab6926a4caf9f278=&trnCardNumber=xxxxxxxxx0412300&trnExpMonth=xx&trnExpYear=xx&aDFinancingType=&aDPlanNumber=&aDGracePeriod=&aDTerm=>';
//--> Explode at the `=` operator and create an array to hold the exploded values
$ex = explode('=', $html);
//--> Run a loop and iterate over the key/value pairs to search for our target
foreach($ex as $key => $value){
//--> Since we exploded at the `=` operator, we know the target string is `&hashValue` iterate through array and find that key/value pair
if($value === '&hashValue'){
//--> We know the hash is the next value in the array, so use the current key + 1 to find the hash
$targetKey = $key + 1;
//--> The next step is not needed if you do not have double quotes after or before the hash.
//--> Simply use the targetKey to get the value of the hash --> $ex[$targetKey]
//--> The following only applies if there is a trailing double quote left on the hash
//--> If you have 6a1562f5c4901522ab6926a4caf9f278" left over
$hash = explode('"', $ex[$targetKey]);
$targetHash = $hash[0];
echo $targetHash;
}
}
退貨:
6a1562f5c4901522ab6926a4caf9f278
現在你可以在任何你喜歡的地方復制 $targetHash 中的散列值......
如果您想更好地理解它是如何工作的,只需在每個步驟后添加一個 print_r() 并查看爆炸如何返回每個步驟的信息......

TA貢獻1828條經驗 獲得超3個贊
$str = '<input type="hidden" name="payFormParams" id="payFormParams" value="payment_type=PaymentForm&merchant_id=117589463&trnType=P&errorPage=%2Fscripts%2Fpayment%2Fpayment%2Easp&approvedPage=&declinedPage=&epe_client_found=false&trnLanguage=eng&shipping_method=&ref1=&ref2=&ref3=&ref4=&ref5=&shippingMethod=&deliveryEstimate=&ordTax1Price=&ordTax2Price=&ordItemPrice=0&ordShippingPrice=0&trnOrderNumber=51029&trnAmount=5%2E00&ordName=Surreal+View&ordEmailAddress=xx%40gmail%2Ecom&ordPhoneNumber=2039581030&ordAddress1=3501+Jack+Northrop+Ave&ordCity=Hawthorne&ordProvince=CA&ordPostalCode=90250&ordCountry=US&paymentMethod=CC&trnCardOwner=Suyash&trnCardCvd=xxx&cavBirthMonth=&cavBirthDay=&cavBirthYear=&cavSin=&paymentAction=&trnCardNumber=xxxxxxxxx0412300&trnExpMonth=xx&trnExpYear=xx&aDFinancingType=&aDPlanNumber=&aDGracePeriod=&aDTerm=&hashValue=6a1562f5c4901522ab6926a4caf9f278">';
$preg='/<input .*?hashValue=(.*?)".*?>/'; //Regular expression
preg_match_all($preg,$str,$array); //Match regular expression
echo $array[1][0]; //return string
- 2 回答
- 0 關注
- 151 瀏覽
添加回答
舉報