在PHP中遇到preg_match()问题[关闭](Having an issue with preg_match() in PHP [closed])
我在PHP上有点生疏,所以请耐心等待。 我正在制作一个简单的电子邮件表单,用于验证几个关键数据。 其中一个字段是提交者的邮政编码。 为了验证这一点,我认为正则表达式很简单,因为我非常有信心可以在一行中完成验证。 看吧:
preg_match("^([0-9]{5}|[0-9]{5}\-[0-9]{4})$", $zip);
这应该与12345和12345-6789相匹配。 但是,这不会发生。 我在这里俯瞰什么?
谢谢!
I am a bit rusty at PHP, so bear with me. I am making a simple email form that validates a few key pieces of data. One of these fields is the submitter's zip code. To validate this, I figured a regex would be simple since I am pretty confident the validation can be done in one line. Behold:
preg_match("^([0-9]{5}|[0-9]{5}\-[0-9]{4})$", $zip);
This should be working to match 12345 and 12345-6789. However, this does not happen. What am I overlooking here?
Thanks!
原文:https://stackoverflow.com/questions/3189559
最满意答案
这里混合了两种不同的API约定。 使用Shared API时不使用
run
上下文,它仅在调用Word API时使用 。 一般来说,我会推荐使用Word API,因为它更新,整体上提供了更多的功能。也就是说,对于此操作,您可以使用Word或Shared API。 我将提供两个例子。
还要注意
.toDataURL()
返回一个包含 base64图像的字符串。 它不是纯粹的base64表示。 您需要删除Word之前的data:image/png;base64,
前缀才能够呈现它。共享API:
既然你只是插入一个图像,我会使用
Office.CoercionType.Image
而不是Office.CoercionType.Html
:Office.context.document.setSelectedDataAsync(imgHtml, { coercionType: "image" }, function (asyncResult) { if (asyncResult.status == "failed") { writeError('Error: ' + asyncResult.error.message); } });
Word API:
Word API包含一个
insertInlinePictureFromBase64
方法。 与setSelectedDataAsync
,它将图像作为Base 64编码的字符串:Word.run(function (context) { context.document.body.insertFileFromBase64(base64String, "end"); return context.sync(); }).catch(function (myError) { // Handle error })
You're mixing a two different API conventions here. You don't use a
run
context when using the Shared API, it is only used when calling the Word API. In general, I would recommend using Word API as it's newer and overall provides a more functionality.That said, for this operation you could use either Word or Shared APIs. I'll provide examples for both.
Also note that
.toDataURL()
returns a string that includes a base64 image. It isn't a pure base64 representation. You need to remove thedata:image/png;base64,
prefix before Word will be able to render it.Shared API:
Since you're simply inserting an image, I would use
Office.CoercionType.Image
instead ofOffice.CoercionType.Html
:Office.context.document.setSelectedDataAsync(imgHtml, { coercionType: "image" }, function (asyncResult) { if (asyncResult.status == "failed") { writeError('Error: ' + asyncResult.error.message); } });
Word API:
The Word API includes a
insertInlinePictureFromBase64
method. As with thesetSelectedDataAsync
, it takes an image in as a Base 64 encoded string:Word.run(function (context) { context.document.body.insertFileFromBase64(base64String, "end"); return context.sync(); }).catch(function (myError) { // Handle error })
相关问答
更多-
实际上,你使用的版本可能并不重要(除非它是2003/4或之前)。 通常,这样做的方法是创建构建块(或快速部分,这是他们在Word 2010中调用的)。 此链接说明了您将采取的基本步骤(尽管如果您不使用Word 2010/13,详细信息会有所不同): https : //support.office.com/en-SG/Article/Word-2010-Create-一个全新的模板- cb17846d-ECEC-49d4-82ea-a6f5e3e8b9ae #__ toc278287931 基本上,您将图像 ...
-
说实话,我仍然不知道你的问题究竟在哪里。 我假设您拥有使用VBA从数据库中获取bookmark name和url知识和代码。 如果是这样,将会有非常简单的代码,允许您将图片从web加载到word文档中的书签。 下面是我测试过的代码的一半成功。 如果我添加任何图片,它将工作正常。 但不会与活跃的谷歌地图的网址一起使用。 我不知道你的意思是什么'静态谷歌地图'(在评论中),你没有提供任何例子,因此你需要自己进行测试。 在运行此测试之前,请确保您的活动文档中有两个书签: bookmark_logo和bookmar ...
-
一种解决方案是使用书签:请参阅https://social.msdn.microsoft.com/Forums/vstudio/en-US/f4f6ecdd-ede9-4f14-83c9-bcad018a444b/insert-image-at-bookmark-position-在字的文档- progamatically-C?论坛= csharpgeneral 而且,如果图像没有显示在Microsoft Word上,这里有一个解决方案: http : //wordfaqs.mvps.org/Invisib ...
-
将图片插入Word文档时如何检索图像文件名(How to retrieve image filename when inserting pictures to Word document)[2022-07-30]
用于添加到Word文档的图像 ActiveDocument.Shapes.AddPicture Anchor:= Selection.Range, fileName:=localFileName, LinkToFile:=True, SaveWithDocument:=True 方法,该链接可用 ShapeOfInterest.LinkFormat.SourceFullName 这仅在文档中存在链接时才有效。 您可以通过在信息屏幕上查看文档,在“相关文档”下面出现“编辑文件链接”菜单项来了解情况。 对于 ... -
如果它只是你要在word文档中添加的图像,那么使用它, Sub FillABookmark(bookmarkname As String, imagepath As String) Dim objWord As Object Dim objDoc As Object On Error Resume Next Set objWord = GetObject(, "Word.Application") If objWord Is Nothing Then ...
-
根据MDN页面 : keep-all值在webkit中未实现(参见WebKit bug 43917 )。 关于SO的类似主题(查看@MrAlien的回答): Safari CSS word-break:keep-all; 不管用 According to MDN page: keep-all value is unimplemented in webkit (see WebKit bug 43917). Similar topic on SO (Check @MrAlien's answer): Safar ...
-
这里混合了两种不同的API约定。 使用Shared API时不使用run上下文,它仅在调用Word API时使用 。 一般来说,我会推荐使用Word API,因为它更新,整体上提供了更多的功能。 也就是说,对于此操作,您可以使用Word或Shared API。 我将提供两个例子。 还要注意.toDataURL()返回一个包含 base64图像的字符串。 它不是纯粹的base64表示。 您需要删除Word之前的data:image/png;base64,前缀才能够呈现它。 共享API: 既然你只是插入一个图像 ...
-
如何使用Aspose.Word在word文档中获取所有已卸载的图像(How can I get all unloaded images in word document using Aspose.Word)[2023-04-10]
我已经解决了我的问题。 我在这里发布我的答案,也许这对其他人有帮助。 var doc = new Document(); var shapeCollection = doc.GetChildNodes(Word.NodeType.Shape, true); // getting all images from Word document. foreach (Shape shape in shapeCollection) ... -
尝试这个 With ActiveDocument.InlineShapes(ActiveDocument.InlineShapes.Count) .Height = 314.95 ' or whatever End With 这假定图片是“与文本一致”(正如您所做的那样)并且是文档中最后一个(最下面的)内嵌图片。 Try this With ActiveDocument.InlineShapes(ActiveDocument.InlineShapes.Count) .Height = 31 ...
-
使用第三方组件:Aspose.Words,它可以为您完成。 Document doc = new Document(MyDir + "Document.doc"); doc.Save(MyDir + "Document.ConvertToHtml Out.html", SaveFormat.Html); 它还支持保存到Png格式。 SaveFormat.Png:呈现文档的页面并将其另存为PNG文件。 use a third party component: Aspose.Words, it can do ...