亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將特定文本從 html 屬性復制到 PHP 字符串?

如何將特定文本從 html 屬性復制到 PHP 字符串?

PHP
阿晨1998 2023-04-28 14:45:45
<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">這是生成的代碼,我制作了一個字符串 $payid,但它復制了整個代碼。我只需要 hashValue=$payid = getStr($html, '< input type="hidden" name="payFormParams" id="payFormParams" value="','">');但我只想將 的價值復制hashValue到那$payid只是6a1562f5c4901522ab6926a4caf9f278 有人可以幫我怎么做嗎?我搞不清楚了。我需要幫助。
查看完整描述

2 回答

?
largeQ

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() 并查看爆炸如何返回每個步驟的信息......


查看完整回答
反對 回復 2023-04-28
?
倚天杖

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


查看完整回答
反對 回復 2023-04-28
  • 2 回答
  • 0 關注
  • 151 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號