Msc Final Project

RegExp escapes ubbcode (php)

Having been tortured by php for already two weeks…The RegExp(Perl) functions between JS and PHP are slightly different: str.match(pattern);—–preg_match($pattern,$str,$arr);…Below escapes ubbcode into html format by PHP RegExp, it’s just like the text editor. <?php $str=”[b]I am bold[/b], [i]I am italic[/i], [b]I am the second bold[/b], [color=red]I am color[/color], [size=7]I am size[/size], [align=center]I am center[/align]”.'<br>’; $ubbcodes=array(‘/\[b\](.*?)\[\/b\]/’,… Continue reading RegExp escapes ubbcode (php)

Msc Final Project

Download your canvas as an image (canvas)

As my website badly needs an online texture generator, downloading canvas becomes a must… The core of code below is “toDataURL()”. <html> <meta http-equiv=”X-UA-Compatible” content=”chrome=1″> <head> window.onload = function() { draw(); var dlButton = document.getElementById(“downloadImageBtn”); bindButtonEvent(dlButton, “click”, saveAsLocalImage); }; function draw(){ var canvas = document.getElementById(“thecanvas”); var ctx = canvas.getContext(“2d”); ctx.fillStyle = “rgba(125, 46, 138, 0.5)”;… Continue reading Download your canvas as an image (canvas)