AS3 BBcode 还是替换技术?
我正在用 AS3/PHP(数据库调用)制作一个网站,我想在主页上加载来自 mySQL 数据库的新闻。使用 AMFPHP 获取纯文本没有问题。但我正在寻找不同的东西。我知道如何在 AS3 中加载图像/YouTube 视频,所以我想用它来增加新闻的趣味性。有什么方法可以输入类似的内容,
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[video]AAAAAAAAAAA[/video]
Donec commodo condimentum enim, vitae consectetur felis pharetra a.
在我的文本之间创建 YouTube API 类的实例并创建两个 TextFields? AS3 没有 BBcode 库,所以我的第二个猜测是......正则表达式。不过,我似乎无法理解这一点,有人想尝试同样的事情并成功吗?
提前致谢。
I'm making a website in AS3/PHP (databasecalls) and I want to load news on the homepage, fed from a mySQL database. No problem to get plain text with AMFPHP. But I'm looking for something different. I know how to load images/YouTube videos within AS3, so I want to spice up the news a little with that. Is there any way I can input something like
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[video]AAAAAAAAAAA[/video]
Donec commodo condimentum enim, vitae consectetur felis pharetra a.
it would make an instance of my YouTube API class right between my text and make two TextFields? There's no BBcode library for AS3, so my second guess was ... regex. Can't seem to wrap my head around that though, anyone ever wanted to try the same thing and succeeded?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对于正则表达式来说是一个完美的工作。
括号
[]
和斜杠/
是保留字符,因此需要用反斜杠转义。[a-zA-Z0-9_-]
是有效 YouTube ID 中可以包含的字符范围。要使用正则表达式,您可以这样进行:
您还可以通过将分配作为 while 条件来将相同的代码压缩为更少的行:
这在功能上是等效的,但可能有点难以掌握。
现在您有了索引和 ID,剩下的就是拆分文本并插入视频!
This is a perfect job for a regular expression.
The brackets
[ ]
and the slash/
are reserved characters, so they need to be escaped with a backslash.[a-zA-Z0-9_-]
is the range of characters that can be in a valid youtube id.To use the regex you go like this:
You can also compress the same code into fewer lines by putting the assingment as the while condition:
This is functionally equivalent, but can be a bit harder to grasp.
Now you have the index and the id, all that remains is to split up the text and insert the video!
您应该能够使其与 String split() 方法一起使用。定义分隔符并使用 split() 方法返回子字符串数组。
这是一个基本示例,我相信您可以对其进行优化......
You should be able to get this to work with the String split() method. Define a separator and use the split() method to return an Array of substrings.
Here's a basic example which I'm sure you can optimize...