小编Gij*_*ijs的帖子

在PHP中生成的Word文档的显示模式

我想将页面导出到.doc文件,但是当我打开生成的.doc时,它会在weblayout-view而不是print-view中打开.这是丑陋和令人困惑的.有没有办法将其设置为打印视图?

我用来生成doc的脚本:

<?php  if(isset($_GET['word'])) {
    header("Content-Type: application/vnd.ms-word");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("content-disposition: attachment;filename=test.doc");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
  <title>Example</title>
  <style type="text/css"> /* SOME STYLING */ </style>
</head>
<body>
  <h1>Hello StackOverflow!</h1>
  <p>Lorem ipsum...</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

现在,我在这里是否可以添加单词复选框☒和单词输入字段?

php ms-word

4
推荐指数
1
解决办法
5579
查看次数

未选中数组中的复选框

我正在构建一个可以添加更多字段组的表单来处理它们我在for循环中读出数组

剧本:

<?php
foreach ($_POST as $key => $value) {
  $$key = $value;
}
$count = count($name);
for ($i=0; $i<$count; $i++){
?>
  <strong><?php echo $name[$i]; ?></strong>  (<?php echo $check[$i]; ?>)<br /><?php echo $select[$i]; ?><br /><br />
<?php
}
?>
<form method="post">
<div class="group">
 <input type="text" name="name[]" /><br />
 <input type="checkbox" name="check[]" value="true" /><br />
 <select name="select[]"><option>1</option><option>2</option><option>3</option></select>
</div>
<div class="group">
 <input type="text" name="name[]" /><br />
 <input type="checkbox" name="check[]" value="true" /><br />
 <select name="select[]"><option>1</option><option>2</option><option>3</option></select>
</div>
<div class="group">
 <input type="text" name="name[]" /><br /> …
Run Code Online (Sandbox Code Playgroud)

php forms arrays checkbox

2
推荐指数
1
解决办法
6926
查看次数

正则表达式内联选项

我有一个文本已经在文本中有可能的值,我想在情境中显示正确的值.我对正则表达式并不是很好,我真的不知道如何解释我的问题,所以这里有一个例子.我几乎让它工作了:

$string = "This [was a|is the] test!";

preg_replace('/\[(.*)\|(.*)\]/', '$1', $string);
// results in "This was a text!"

preg_replace('/\[(.*)\|(.*)\]/', '$2', $string);
// results in "This is the test!"
Run Code Online (Sandbox Code Playgroud)

这没有问题,但是当有两个部分时它不再起作用,因为它从最后一个获得结束括号.

$string = "This [was a|is the] so this is [bullshit|filler] text";

preg_replace('/\[(.*)\|(.*)\]/', '$1', $string);
//results in "This was a|is the] test so this is [bullshit text"

preg_replace('/\[(.*)\|(.*)\]/', '$2', $string);
//results in "This filler text"
Run Code Online (Sandbox Code Playgroud)

情境1应该是(和|之间的值,而情况2应该显示|和之间的值).

php regex

1
推荐指数
1
解决办法
65
查看次数

标签 统计

php ×3

arrays ×1

checkbox ×1

forms ×1

ms-word ×1

regex ×1