我有一个PHP会话variables$_SESSION['user'] ,在整个会话中都处于活动状态。 在头部分,我有我的JavaScript文件, scripts.js 。 如果我需要像下面这样的东西,如何将会话variables传递到JavaScript文件中。 $.("#btn').click ( function() { alert('<?php echo $_SESSION['user']; ?>'); } ) 由于JavaScript文件中没有识别<?php ?> ,所以上面的代码不起作用。 所以我必须把自己的PHP文件,但我怎么把它保存在JavaScript文件?
我有一个.csv文件数据 Date,Name,Call Type,Number,Duration,Address,PostalCode,City,State,Country,Latitude,Longitude "Sep-18-2013 01:53:45 PM","Unknown","outgoing call",'123456',"0 Secs","null","null","null","null","null",0.0,0.0,,, "Sep-18-2013 01:54:14 PM","Unknown","outgoing call",'1234567890',"0 Secs","null","null","null","null","null",0.0,0.0,,, "Sep-18-2013 01:54:37 PM","Unknown","outgoing call",'14772580369',"1 Secs","null","null","null","null","null",0.0,0.0,,, 并使用下面的代码将数据插入到数据库中 $sql = "LOAD DATA INFILE `detection.csv` INTO TABLE `calldetections` FIELDS TERMINATED BY '".@mysql_escape_string(","). "` OPTIONALLY ENCLOSED BY `".@mysql_escape_string("\""). "` OPTIONALLY ENCLOSED BY `".@mysql_escape_string("\'"). "` ESCAPED BY `".@mysql_escape_string("\\"). "` LINES TERMINATED BY `".",,,\\r\\n". "`IGNORE 1 LINES `" […]
我currentyl没有线索如何sorting在PHP中包含UTF-8编码string的数组。 该数组来自LDAP服务器,所以通过数据库sorting(没有问题)是没有解决scheme。 以下不能在我的Windows开发机器上工作(虽然我认为这应该是至less一个可能的解决scheme): $array=array('Birnen', 'Äpfel', 'Ungetüme', 'Apfel', 'Ungetiere', 'Österreich'); $oldLocal=setlocale(LC_COLLATE, "0"); var_dump(setlocale(LC_COLLATE, 'German_Germany.65001')); usort($array, 'strcoll'); var_dump(setlocale(LC_COLLATE, $oldLocal)); var_dump($array); 输出是: string(20) "German_Germany.65001" string(1) "C" array(6) { [0]=> string(6) "Birnen" [1]=> string(9) "Ungetiere" [2]=> string(6) "Äpfel" [3]=> string(5) "Apfel" [4]=> string(9) "Ungetüme" [5]=> string(11) "Österreich" } 这是完全废话。 使用1252作为setlocale()的代码页提供了另一个输出,但仍然是一个明显错误的: string(19) "German_Germany.1252" string(1) "C" array(6) { [0]=> string(11) "Österreich" […]
我目前使用curl来填充表单,但是在完成后,处理表单的其他脚本被redirect到其他url,现在我想要获取url,脚本被redirect到一个variables。 谢谢..
我一直在看官方的PHP文档,但我无法find我在找什么。 http://php.net/manual/en/function.parse-ini-file.php 我只想要一个函数来编辑和读取php ini文件中的值,例如, [default_colors] sitebg = #F8F8F8 footerbg = #F8F8F8 link = #F8F8F8 url = #F8F8F8 bg = #F8F8F8 text = #F8F8F8 border = #F8F8F8 lu_link = #F8F8F8 lu_url = #F8F8F8 lu_bg = #F8F8F8 lu_text = #f505f5 lu_border = #F8F8F8 如何读取属于“lu_link”或“footerbg”的值? 如何为这些地方写一个新的价值?
林想知道,如果它是一个很好的做法传递引用,当你只是读一个variables,或者如果它应该总是作为一个值传递。 通过引用的示例: $a = 'fish and chips'; $b = do_my_hash($a); echo $b; function &do_my_hash(&$value){ return md5($value); } 传递值示例: $a = 'fish and chips'; $b = do_my_hash($a); echo $b; function do_my_hash($value){ return md5($value); } 哪个更好 ? 例如,如果我要循环1000轮? 循环的例子: for($i = 0 ; $i < 1000 ; $i++){ $a = 'Fish & Chips '.$i; echo do_my_hash($a); }
一些真正想知道但从来没有发现的东西是PHP中的捷径。 我目前正在使用foreach循环编写一个函数,只有一个语句。 我试图省略大括号,因为你可以在if / else控制结构中进行操作。 没有错误。 foreach($var as $value) $arr[] = $value; 现在我试图用同样的方法,但是把一个if / else块放在里面。 再次,工作,没有错误。 foreach($var as $value) if(1 + 1 == 2) { $arr[] = $value; }; 然后,我想,“为什么这个工作?” 并省略了结束分号。 还在工作。 所以我试图在foreach循环中使用if / else语句而不使用大括号,并且仍然工作,没有错误。 但是,foreach循环现在真的closures/结束了吗? foreach($var as $value) if(1 + 1 == 2) $arr[] = $value; 至less我再次省略了结尾分号,并且(按预期)发生了一个parsing错误。 所以我的大问题是:什么时候可以省略花括号和结构/循环/函数? 我知道我可以在if和else这样做。 但是,什么while ,为什么和foreach ? 是的,我知道这是不安全的,聪明的,无论代码没有大括号,还有像$condition ? […]
当插入PHP的string索引数组元素(5.3.3,Win32)时,可能会出现以下行为: $ha = array('key1' => 'Hello to me'); print $ha['key1']; # correct (usual way) print $ha[key1]; # Warning, works (use of undefined constant) print "He said {$ha['key1']}"; # correct (usual way) print "He said {$ha[key1]}"; # Warning, works (use of undefined constant) print "He said $ha['key1']"; # Error, unexpected T_ENCAPSED_AND_WHITESPACE print "He said $ha[ key1 […]
说我有一个关联数组: array( "color" => "red", "taste" => "sweet", "season" => "summer" ); 我想介绍一个新的元素: "texture" => "bumpy" 在第二项后面,但保留所有的数组键: array( "color" => "red", "taste" => "sweet", "texture" => "bumpy", "season" => "summer" ); 有没有这样的function? array_splice()不会削减它,它只能使用数字键。
我正在使用PHP,并且正在制作表单发布到的操作页面。 页面检查错误,如果一切正常,它会将它们redirect到发布数据的页面。 如果没有,我需要将它们redirect回到他们在页面上的错误和POSTvariables。 这是它的工作原理。 HTML看起来像这样… <form name="example" action="action.php" method="POST"> <input type="text" name="one"> <input type="text" name="two"> <input type="text" name="three"> <input type="submit" value="Submit!"> </form> action.php看起来像这样… if(error_check($_POST['one']) == true){ header('Location: form.php'); // Here is where I need the data to POST back to the form page. } else { // function to insert data into database header('Location: posted.php'); […]