Jump to content

bobbinsbro

Members
  • Posts

    385
  • Joined

  • Last visited

    Never

Everything posted by bobbinsbro

  1. thank you very much, that did the trick. i didn't know about greedy and non-greedy. nice to learn new things.
  2. the pattern i gave is part of a much longer pattern, that is supposed to match long blocks of text containing many quote-delimited strings. i originally tried what you suggested, but preg_match() didn't stop at the first quote (the one on which i need to end the sub-pattern) but rather continued to the very last quote, counting all intermediate quotes as part of the (.*) sub-pattern. so i tried using matching any character that isn't the backreference to force preg_match() to stop on the first quote found. i need to use the back reference because i need to allow both single and double quotes in all places, and i can't know which in advance. example of a string i want to match: and the pattern $pattern = '/(\'|")([^\1])(\1)/s'; should match only but doesn't match anything. using $pattern = '/(\'|")(.*)(\1)/s'; matches which is not what i want
  3. the problem is that doesn't work. i'm trying to get the contents of a string delimited by either double quotes ("...") or single quotes ('...'). the regex i'm using is: $pattern = '/(\'|")([^\1]*)(?:\1)/s' that doesn't work. however, changing it to $pattern = '/(\'|")([^\']*)(?:\1)/s' does work (assuming the string is delimited by single quotes). i checked and made sure that \1 contains a single or double quote (used preg_match() with the optional &$matches argument and print_r()'ed $matches to see what is in the sub-patterns). as a result, i assume either i can't use a backreference in a character class or i'm doing something wrong.
  4. regular expressions http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax or if the string inside which the substring you want is static (always the same) you could use strcmp (case sensitive), strcasecmp (case insensitive), substr, strstr or something similar (chack out the functions on this page http://us2.php.net/manual/en/book.strings.php.
  5. hi all how would i go about using a backreference in a character class in a pcre regex pattern? example of something similar to what i want to do: $pattern = '/(abc)([^\1]).*/'; thanks in advance bob
  6. hi phpfreaks i need to test to see if a static method is declared in an abstract class. i can't use method_exists() because that requires an instance of the class. i looked at is_callable(), but it looks like i would have the same problem there. is there a way to check if a static method is declared in an abstract class without having to use a try...catch block to find out by way of trial and error? thanx in advance.
  7. hi all. i am working on a website for a client whose host only allows uploads to be up to 8MB per file. users of this site may legitimately attempt to upload larger files. is there any way to make the client post the file in chunks and reassemble them on the server? i found a thread on a different forum referring to a java applet that does this, but i'd rather use a php solution if at all possible. i thought i'd try to use javascript to split the file into chunks and send each chunk with an XHR, but i discovered only IE allows file manipulation in js via active-x (which makes sense, as allowing js to manipulate files would be a tremendous security problem). is there anyone out there who has any inkling how this can be done in a java-free way?
  8. set the method attribute in the html <form> to be method="post" (like this <form method="post") and in the php code retrieve the variables via the $_POST superglobal instead of the $_GET.
  9. hi all. i'm using an <object> tag to load dynamic content into a static html template without using javascript (otherwise i would use a <div>). i would like the size of the <object> to stretch to the size of the content, like a div does. basically, i want to have to scroll the page and not the <object>. is there any way to do this, or should i consider a different solution? i really want to do achieve this (or a similar result) without using javascript. thanx in advance.
  10. figured it out for myself. i was including the static html into index.php, so all the paths would have to be relative to index.php and not to the html file as i was doing. silly me.
  11. hi all. i'm using an <object> tag to load dynamically generated content (by a php script) into a static .html page. the idea is to have only the contents of a certain <div> change without using javascript. my html looks like this: <html> <head> <title>a page</title> </head> <body> a page <div> <!--[if IE]> <object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="content.html"> Dynamic page content </object> <![endif]--> <!--[if !IE]> <--> <object type="text/html" data="content.html"> Dynamic page content </object> <!--> <![endif]--> </div> </body> </html> i got the conditional comments from some website after discovering that IE needed the clsid. my problem is that for some reason i can't fathom, instead of loading content.html, what gets loaded into the object are another copy of the above html in which the alt object text appears (see attached screenshot of the page in FF 3.0.6). the page is stored in /public/html/ and so i content.html. however, the page is called by index.php which resides in /public/. when i tried setting data="/content.html", instead of the page being nested, i get the alternate object text. the same happens when i try data="/html/content.html". a few examples of things i tried putting in content.html: 1) <html><body>index page</body></html> 2) index page what am i doing wrong? thanx in advance. [attachment deleted by admin]
  12. i will definitely use that. i was using simpleXML because i thought that it had less of a memory footprint (since it's a so much smaller class), but i didn't test my theory, which was a bit daft of me. i just ran a test, and the difference is about 100 bytes... i feel kinda silly. thanx Dj Kat.
  13. ok. in more depth. this is a permissions editing thing. the permissions are stored as an xml string in a DB. i get said string from the db, load it into a simplXMLElement. in the bit of code i pasted, i'm changing a user's permissions. heres the logic: that's what the code posted above does. an example: before i run the code <security> <perm1> <user>1</user> <user>2</user> </perm1> <perm2> </perm2> <perm3> </perm3> </security> now, i edit user 2, and move him to perm2 node. this is the result in the DB: <security> <perm1> <user>1</user> </perm1> <perm2> <user>2</user> </perm2> <perm3> </perm3> </security> i dumped the contents of the temporary xml string (the variable $xmlStr) and the '<' '>' characters are intact. then i dumped the simpleXMLElement object after i set $xmlStr into the permission node, and the '<' changed to '<'. as i said, i tried doing the same thing with addChild() with the same results. i should note that in a different place in the same code i use addChild() and the xml is created just fine. is there a way to prevent simpleXML from htmlentities()-ing my xml string (since i think that this is a security measure of the simpleXML class)?
  14. i checked out the source HTML of both the working html and the faulty php-generated html. the php 1 just stops here: <td class="sponsorbg"><table width="90%" border="0" align="center" cellpadding="0" cellspacing="5"> <tr> <td align="center"> </td> </tr> <tr> the working html continues for a quite a while and ends properly (</html>). as a result, there's probably a fatal php error here (this is the php code immediately after the point where the faulty html ends): <?php $randoms = array(); $start =1; $total =11; while (count($random) < 3) { $random = mt_rand($start,$total); if (!in_array($random, $randoms)) { $randoms[] = $random; } } $captions = array("RBC","Prodomax","Liews Motors","Advanced Motion Controls","Burnside","TD Canada Trust","Reinhart","SCDSB","ARO","Stayner Lions","test","ComTek"); $urls = array("http://www.royalbank.com", "http://prodomax.com/","http://a-m-c.com/","http://www.rjburnside.com/","http://tdcanadatrust.com","http://www.reinhartfoods.com/", "http://www.scdsb.on.ca/", "http://www.aronet.com/", "http://www.lionsclubs.org/","test","http://www.comtekcomputers.com/"); for ( $i = 0; $i < 3; $i++){ print $randoms[$i]; $caps = $captions[$randoms[$i]];; $img = $urls[$randoms[$i]]; } ?> turn on error reporting and post any errors you get when loading the page please
  15. require/include return true/false for success/failure. to get the contents of a file into a variable use file_get_contents('filename);
  16. add quotes to your definition: define('MEDIA_HEIGHT', 120);
  17. the $ should be there - the $permission variable contains the name of the node i am trying to change. e.g.: $permission = 'perm1'; $securityXML->$permission == $securityXML->perm1; //true
  18. hi guyz. i'm having a very weird problem with simpleXML. here's the troublesome bit of code: $xmlStr = ''; foreach ($securityXML->$permission->children() as $child){ if ($user != strip_tags($child->asXML())) $xmlStr .= $child->asXML(); } unset($child); $securityXML->$permission = $xmlStr; my problem is that $xmlStr contains valid xml (e.g., '<some_node>some_value</some_node> etc.) but after being set as the contents of $permission, the xml string looks like it was passed through htmlentities() (all the '<' are turned to <, all '>' are turned to > etc.). i tried appending $xmlStr as a child of $permission with the asChild() method, with the same results (only the xml string wasn't where i wanted it ). the main xml object looks something like this before i add the $xmlStr: <security> <perm1> <user>user_id</user> </perm1> <perm2> </perm2> <perm3> </perm3> </security> after i add the $xmlStr it looks like this: <security> <perm1> <user>user_id</user> </perm1> <perm2> <user>user_id</user> </perm2> <perm3> </perm3> </security> does any1 have any idea what's going on?
  19. thanx guyz. @elgoog - now why didn't i think of that... :-\ duh thanx. @Mchl - thanx for the references. i will definitely take a look at those.
  20. hi every1 i have recently joined a project in full swing ( = there's a s**t load of written code). this project runs an install script that creates and initializes a new database, creates new users in the database users table and creates a settings file. i've been helping debug this install process, and everytime the install fails, i have to go througha routine of DROPping users from the DB, DROPping the shcema and deleting the settings file. 1 of my assignments is to write rollback code, so that when an install fails, we won't have to keep reverting changes manually. in most cases, on script error, the php die() function is called. it is called in a whole lot of places... i was wondering if there was a way to re-declare die() at the global scope with enhanced functionality (the functionality needed to revert the crashed install), so that i don't have to go through all the files in the project (over 700 files) and change every die() function the a custom uninstall() function. please tell me there's a way to do this... it will probably be a temporary change (changing die is unsafe in the long term, i know), but it would make the debugging of the install so much more productive. what i would like to do is something like this: <?php //in the global scope function die($msg){ //drop users from database users table //drop schema //unlink('settings_file'); echo $msg; exit; } ?> if you think i'm coming at this problem from the wrong direction, please share your thoughts/recommendations/ideas. they are all welcome. thanx in advance, bobbinsbro
  21. first of all, in the future please use the code tags. (the button with the # on it in the post editor). as for your problem: 1) change preg_replace() with str_replace(). i have seen it written all over the place that str_replace() is the preferred function for simple replaces (such as yours). 2) move the replace line up before the $filepath definition line like so: $fileName = str_replace(' ', '_', $fileName); $username = $_SESSION['username']; $filePath = $uploadDir . $filename; (note the use of code tags ). good day.
  22. thanx for your help. i'll have to assume it's something wrong on my machine. i'll create a test run on the server on which things will eventually run. g'day
  23. i installed 5.1.3 (using utf-8 charset by default). didn't work. when i do "select * from sheet1 (this is the name of the table) order by col;" in the mysql command line, the order of the output is 1, 7, 8, 2, 3, 4, 5, 6 (same problem as before). just doing "select * from sheet1;" in the command line gives the proper order (1, 2, 3, 4, 5, 6, 7, 8 ) and doing "select * from sheet1 order by bla;" gives the expected results (8, 7, 6, 5, 4, 3, 2, 1). the table is set to use utf-8 (i posted the creation code perviously). what gives? ???
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.