如何使用PHP将连字符 - 放入word文档中

时间:2015-09-22 06:24:22

标签: php html string com hyphen

我在使用连字符时遇到问题 - 在字符串中使用如下字体。由于连字符在字体中用作某个字符。 那么如何将此连字符放入使用所述字体的字符串中。

$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Documents->Add();
$word->Visible = 1;
$word->Selection->Font->Name = 'malfont';
$word->Selection->TypeText("Hi - Hello - How - are - you");

我得到一个输出 - 缺少但如果我将字体名称更改为'Calibri',那么我将得到连字符。那么我怎么能避免这种情况呢。

1 个答案:

答案 0 :(得分:0)

根据Mattias Lindberg的建议,每次检测到连字符时我都会切换字体,这对我有用....

$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Documents->Add();
$word->Visible = 1;
$word->Selection->Font->Name = 'Calibri';
$word->Selection->TypeText("Hi - Hello - How - are - you");
$word->Selection->Font->Name = 'malfont';
$word->Selection->TypeText("Content of the mal font");