[PHP] preg_replace and eval
Hey there, We have a class that sets up a tree structure that represents an e-learning object made up of nested "components". We have a function getPropertyValue($name) which returns the property $name for the current component. Now, we want to allow the user to use something like {parent.property} in a property value, so that it can inherit parts of properties from the parent component. For example: caption = "the name of this component's parent is {parent.name}!" The following line sort of works: $retVal = preg_replace("/(.*){parent.(.*)}(.*)/e","'\\1'.\$this->parentNode->getProper tyValue('\\2').'\\3'",$retVal); However, if there are more than one string to replace it only works on the last one. So: caption = "the parent's coordinates are ({parent.left}, {parent.top})" would only return something like: "the parent's coordinates are ({parent.left}, 100)" Hope someone can help. Thanks Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Stripping illegal characters out of an XML document
Hi there. I'm working with RDF/XML that is strict on what characters are allowed within the elements and attributes. I was wondering if anyone had a script that processed a string and replaced all illegal-characters with their HTML code, for example "&" is converted to & and " to ". It should also work for characters like "é". It would be possible to process the strings before they are inserted into the XML document - if that is easier. If there isn't a script that'll do this I'll have to write my own - which could be quite time consuming ;( Thanks Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping illegal characters out of an XML document
Thanks, I've created a delimited file of all the HTML Character references. I then loop through and do a replace as previously suggested. However, IE's XML Parser still doesn't like the é which represents é For all intents and purposes it's ok and works with the RDF processor. However, I'd like IE to be able to view the XML file just for completeness. Da "Analysis & Solutions" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Thu, Jun 06, 2002 at 12:47:57PM +0100, Daniel Pupius wrote: > > > Hi there. I'm working with RDF/XML that is strict on what characters are > > allowed within the elements and attributes. I was wondering if anyone had a > > script that processed a string and replaced all illegal-characters with > > their HTML code, for example "&" is converted to & and " to ". It should > > also work for characters like "é". > > Here's what I use. I grab the file and stick it into the $Contents > string. Then, I clean it up with the following regex's. Finally, I > pass it to the parse function. > ># Escape ampersands. >$Contents = preg_replace('/(&|&)/i', '&', $Contents); > ># Remove all non-visible characters except SP, TAB, LF and CR. >$Contents = preg_replace('/[^\x20-\x7E\x09\x0A\x0D]/', "\n", $Contents); > > Of course, you can similarly tweak $Contents to drop or modify any other > characters you wish. > > That's snipet is from my PHP XML Parsing Basics tutorial at > http://www.analysisandsolutions.com/code/phpxml.htm > > > > It would be possible to process the strings before they are inserted into > > the XML document - if that is easier. > > While that's nice, it's not fool proof. What if someone circumvents > your insertion process and gets a bad file into the mix? You still need > to clean things as they come out just to be safe. > > Enjoy, > > --Dan > > -- >PHP classes that make web design easier > SQL Solution | Layout Solution | Form Solution > sqlsolution.info | layoutsolution.info | formsolution.info > T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y > 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can i resize images after upload?
Why not use PHP's built in image library: http://www.php.net/manual/en/ref.image.php -- it's pretty cool. The resample function doesn't exist in some old install but it's quite easy to write your own -- just doesn't run as fast as a compiled version. Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] What do you say to someone who says...
What do you say to someone who says: "PHP is just a kiddie language"? (Source: http://www.dhtmlcentral.com/forums/topic.asp?TOPIC_ID=19373) PHP is currently my strongest development language and it annoys me that it is a much less bankable skillset than .NET and Java. How long do you think it's going to take to get respect? Will it ever happen? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Starting OOP
It would be a good idea to create a database abstaction class. This means that should you move your application to a different database you only have to replace your database class, instead of recoding everything with the new set of functions. It can also be neater than using the mysql functions directly. You could use it as in a composite or an aggregated relationship. Check out http://www.phppatterns.com/index.php/article/articleview/15/1/1/ for some useful information. Also is it necessary to have $ponum sent to each function, how about creating an attrbute of the class and setting it in the constructor function. "Mike Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I've been doing procedural coding for a few month's, but perceive the > need for OOP for some of the projects I've done. I'm starting out and > and would like some feedback, before I tread down the wrong path. The > books I'm looking at Professional PHP (Wrox), and Visual QuickStart PHP > have examples, but I seem to need something more concrete so I've > started a skeleton to rewrite a Purchase Order application. Here is the > layout: > > class PurchaseOrder > { > //Variables > var $ponum; //This will be a $_SESSION variable if that matters > var $item; > > function AddItem($ponum,$item){ > ...INSERT SQL CODE > } > > function DeleteItem($ponum,$item){ > ...DELETE SQL CODE > } > > function UpdateItem($ponum,$item){ > ...UPDATE SQL CODE > } > > function ListItems($ponum){ > ...SELECT SQL CODE, RETURN RESULTS (ie. > while($row=mssql_fetch_array($rst)){echo $row[0]}) > } > > } > ?> > > I would then include that in my page, > and add items to a PO by doing something like > include('pocode.php'); > $po = new PO(); > > If($_POST['submit']=='Add'){ > //A HTML Button next to a text box to add a line item > $po->AddItem('12345','5063'); > } > > $po->ListItems('12345'); > > ?> > > Do I have the basic concept right? This is like relearning to code. > Perhaps I learned in a bad way if that's the case. Any especially good > tutorials or books to recommend? > > Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: RewriteRule REGEX ?
I don't think you need to escape the full-stop (period) that could cause problems. I've used the following rule with no problem: RewriteRule ^learning/(.*).htm$ _rewriteHandler.php?query=$1/ "Monty" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > My server runs Apache 2.0. I am trying to do a simple URL rewrite so that > old URLs will map to our new style of URLS... > > From This: articles.php?id=999 > To This:articles/999 > > In the .htaccess file for the htdocs folder that contains the web files, I > put the following: > > RewriteEngine on > RewriteRule ^articles\.php\?id=([0-9]+)$ articles/$1 [R] > > I've also tried this (no slash in front of ?): > > RewriteEngine on > RewriteRule ^articles\.php?id=([0-9]+)$ articles/$1 [R] > > But I keep getting a 404 error for articles.php, which means that something > must be wrong with my RewriteRule because it's not matching. I've tried > various tweaks and just can't get it to work. > > What am I doing wrong?? > > Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: send a POST to a URL from within PHP code
You need to open a socket: http://uk.php.net/manual/en/function.fsockopen.php Think there's a demo in the comments lower down the page. Yup, here it is: function httpPost($host, $path, $referer, $data) { $fp = fsockopen($host, 80); fputs($fp, "POST ".$path." HTTP/1.0\r\n"); fputs($fp, "Host: ".$host."\r\n"); fputs($fh, "Referer: ".$referer."\r\n"); fputs($fp, "Content-type: application/x-www-url-encoded\r\n"); fputs($fp, "Content-length: ".strlen($data)."\r\n"); fputs($fp, "\r\n"); fputs($fp, $data."\r\n"); fputs($fp, "\r\n"); $tmp_headers = ""; while ($str = trim(fgets($fp, 4096))) $tmp_headers .= $str."\n"; $tmp_body = ""; while (!feof($fp)) $tmp_body .= fgets($fp, 4096); fclose($fp); return $tmp_body; } "Vincent Dupont" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Hi all, I would like to simulate sending a form in POST to a specified URL through PHP. I knwo how to do this from a HTML form : http://url.com/query";> blablabla I would just like to simulate this because I have some processes that will change the values of the form before sending it to the 'action' URL With a GET, the fields would be included into the query strinbg, so this is quite easy. What happens in a POST? Any idea is welcome Vincent mailto: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Create a zip archive from a folder
I have achieved this using the shell_exec() function: $cmd = "cd ".escapeshellarg($curdir).";zip -r9b . ".escapeshellarg($name)." *"; $result = shell_exec($cmd); This moved the shell into the current directory ($curdir), then creates a new zip file ($name) for the entire directory. I have noticed that shell_exec() has unexpected results with certain commands, i.e. if it fails you won't always get the same message that you'd get at the command prompt. "Matt Palermo" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello. Does anyone know how I can easily create a zip archive from a folder > on my server? I have a library class that will do this for a tar file (I > just give it the folder name and the archive name and it creates the tar > file for me very easily). I was wondering if there is anything really easy > like this for creating zip files. Please let me know. > > Thanks, > > Matt > http://sweetphp.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php