Day: October 9, 2018

PHP: 模拟 POST 提交表单, Sending POST data without form, send a POST request with PHP

  方法有很多种,比如用 AJAX: $.post('/foo.php', { key1: 'value1', key2: 'value2' }, function(result) { alert('successfully posted key1=value1&key2=value2 to foo.php'); }); 又比如用CURL: function httpPost($url, $data) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl);

JavaScript: 文本替换, 替换全部, 正则替换文本, How to replace all occurrences of a string in JavaScript?

一次 replace只能替换一个,例如: var str = 'test test test test' console.log(str.replace('test', 'tester')) 通过正则可以一下替换全部: someString = 'the cat looks like a cat'; anotherString = someString.replace(/cat/g, 'dog'); // anotherString now contains "the dog looks like a dog"     更多参考:http://www.tizag.com/javascriptT/javascript-string-replace.php   本文:JavaScript: 文本替换,… Read More