用图像替换字母(来自短语)
$q = "my phrase with special chars like úção!?";
while ($i < strlen($q)) {
echo '<img src="'.$q[$i].'.png" />';
$i++;
}
我也尝试过使用 switch/case,但是当我有像 ç ã â 这样的字符时,我无法让图像替换工作,因为它有多个字符(我正在转换为 HTML 实体,然后在 case ccedil 中搜索,但它不是可能)
谢谢
$q = "my phrase with special chars like úção!?";
while ($i < strlen($q)) {
echo '<img src="'.$q[$i].'.png" />';
$i++;
}
I also tried with switch/case but when I have chars like ç Ç ã â I can't get the image replacing to work since its more than one char (i was converting to HTML entities and then searching in the case ccedil but it's not possible)
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不起作用,因为文件名中不允许使用重音符号。
解决方法:尝试使用受支持的名称来命名图像文件。例如:
é
=>eacute
使用此代码:
此代码还支持空格。不过,您需要一个名为 space.png 的图像。
这是生成的输出:
< img src="s.png" //>
It won't work because accents aint allowed in a file name.
A workaround: Try naming your image file with accents with a supported name. Eg:
é
=>eacute
With this code:
This code also support space. You need an image named space.png though.
Here is the generated output:
<img src="m.png" /><img src="y.png" /><img src="space.png" /><img src="p.png" /><img src="h.png" /><img src="r.png" /><img src="a.png" /><img src="s.png" /><img src="e.png" /><img src="space.png" /><img src="w.png" /><img src="i.png" /><img src="t.png" /><img src="h.png" /><img src="space.png" /><img src="s.png" /><img src="p.png" /><img src="e.png" /><img src="c.png" /><img src="i.png" /><img src="a.png" /><img src="l.png" /><img src="space.png" /><img src="c.png" /><img src="h.png" /><img src="a.png" /><img src="r.png" /><img src="s.png" /><img src="space.png" /><img src="l.png" /><img src="i.png" /><img src="k.png" /><img src="e.png" /><img src="space.png" /><img src="uacute.png" /><img src="ccedil.png" /><img src="atilde.png" /><img src="o.png" /><img src="!.png" /><img src="questionmark.png" />
我会使用诸如 百分比编码又名 URL 编码 之类的映射,因为文件系统——假设该短语包括“../../etc/passwd”——以及糟糕的(或缺失或不同的)unicode 实现。
Wiki 有一些关于 HTML 中的 Unicode 的信息;确保在 Content-Type 中将正确的编码提示返回到浏览器(例如,不要依赖默认值),并且您的 FS(和 PHP/Web 服务器访问)允许使用 Unicode 的名称和/或“会说话” " 相同的编码(UTF-8/百分比编码或其他)。
另外,HTTP/URI 不能“理解”Unicode,只能理解 ASCII。请参阅 URL 中的 Unicode 字符,其中讨论了所使用的常见编码。现代浏览器将自动进行编码(同时仍然在地址栏中显示 unicode 字形等)。然而,依赖浏览器自动执行此编码意味着不知情的浏览器将无法正常运行。因此,回到第一段。
I would use a mapping such as Percent Encoding aka URL encoding because of various mismatches between the file-system -- imagine the phrase includes "../../etc/passwd" -- and poor (or absent or differeing) unicode-implementations.
Wiki has some about Unicode in HTML; make sure that the correct encoding hints are returned to the browser in Content-Type (e.g. don't rely on the default) and that your FS (and the PHP/web-server access) allow names with Unicode and/or are "talking" the same encoding (UTF-8/percent-encoded, or otherwise).
Also, HTTP/URIs doesn't "understand" Unicode, only ASCII. See Unicode characters in URLs which talks about the common encoding(s) used. Modern browsers will do the encoding automatically (while still showing the unicode glyphs in the location bar, etc.). However, relying on a browser to do this encoding automatically means that unaware browsers will not act properly. Hence, back to paragraph one.