Jump to content

ThePsion5

Members
  • Posts

    203
  • Joined

  • Last visited

Everything posted by ThePsion5

  1. Yeah, I was just hoping I wouldn't have to do that, lol, since I also want to be able to access and iterate through the $Misc array without having to worry about empty keys. It doesn't look like there's any other way to do it, unfortunately.
  2. What CSS formatting, specifically, isn't working? If there's anything like an unclosed tag in your topmenu.php file that could be causing the problem, I'd start by checking there.
  3. Hi guys,A function I'm creating iterates through an array with a certain number of important values by seeing if the appropriate array key exists. I also want to store any other values in the array, but be able to use the count() function to get an accurate number of values, not including the important values mentioned above. This was my first attempt: //Retrieve the important values$this->important = $Attributes['important'];$this->important2 = $Attributes['important2'];$this->important3 = $Attributes['important3'];//Remove them from the array$Attributes['important'] = null;$Attributes['important2'] = null;$Attributes['important3'] = null;//Save the rest as unimportant values$this->Misc = $Attributes; This removes the information from the array, but when I call count on it, it still counts the empty array keys (so if there were 3 important attributes and 3 unimportant ones, count() still returns 6 after i've set the value of the important keys to null).I'd rather not have to make a coding structure to copy the unimportant array values, mostly because i'd be a pain in the arse. Is there a way for me to remove keys from an array?
  4. 1. Is the CSS not functioning at all, or just now how you intended it to function? If it's not working at all, most likely you have some error in your reference to the CSS, although I'm not sure how including the file would cause this.2. Check your included file for any unclosed tags - these are the most likely thing that would hurt your CSS formatting3. Are you using any CSS that selects elements by order? I'm not even sure if you can do that in CSS2 or not, but including the other file might offset the order of certain elementsThe best way to check your CSS for errors is to put debugging info in, like giving all your <table> and <div> tags 3px wide red borders and setting a different background color for your main CSS classes, that should show you alot of information about what's going on.
  5. It's not so difficult as it seems...take this database schema, for exampleTable Images:ID (Integer) auto-increment primary keyURL (Varchar)Title (Varchar)Alt (Varchar)Caption (Text)ShowOnDate (Date) default nullAssuming you can insert the images with an auto-incrementing ID and the images start at ID 1, this simple script should show a new image every day, and even check to see if it should show a specific image on a certain day //Database connection code up here//Find out how many total images$Result = mysql_query('SELECT COUNT(*) FROM Images');$numPics = mysql_result($Result, 'COUNT(*)', 0);//Get the current day$date = getDate();$day = $date['yday'];//Check to see if there's a specific picture to be displayed on this day$date = $date['year'] . '-' . $date['mon'] . '-' . $date['mday'] //formats as 'YYYY-MM-DD'$Result = mysql_query("SELECT * FROM Images WHERE ShowOnDate='$date'");//If we don't find a date specific image, display the image of the dayif(mysql_num_rows($Result) == 0){//Find out which picture to display$DisplayedID = $day % $numPics;//In case you aren't familiar with the modulus operator, it finds the remainder if $day is divided by $numPics$Result = mysql_query("SELECT * FROM Images WHERE ID=$ID");}//Display the image here This should do exactly what you specified...although I feel like it's probably not the most efficient, considering that it takes 3 calls to the database in order to find an image, lol. Hope this helps.
  6. Hah, that's what the problem is, then. It works now without any problems. Thanks!
  7. It seems like you're trying to perform a simple string replace function with this code, why not use PHP's string replace function? If that's not the case, you'll have to more clearly tell us what's happening and what you want to happen.
  8. Unfortunately, I'm still stuck on my second regular expression designed to match attributes. My modified regular expression looks like this: \w+\s*=\s*("|')?[^\1]+\1 \w+\s* - Matches 1 or more 'word' characters and any number of whitespace characters=\s*("|')? - Matches the equal sign, any number of whitespace characters, and 0-1 single or double quote values[^\1]*\1 - Matches a 0 or more characters not equal to the end quote and the end quote itselfI'm still not sure why this doesn't work...testing it with the string href="http://www.google.com" title="Google" returns the entire string as a match. Any ideas?EDIT: I've tried breaking th regex into bits and work with them from their...this is the segment that should match the attribute values: =("|\')[a-zA-Z]+\1But this returns the entire test string as well, which seems very strange to me...I wonder what may be up? I feel like I'm missing something very basic.
  9. That actually worked out very well, thanks :)Now I have another, slightly more complex difficulty - I'm trying to parse out the attributes of a HTML/XML tag using a regular expression, this is what I have so far:This code matches the tag itself: <[\s\S]+> And this code matches the attributes and their respective values: [\S]+[\s]*=[\s]*(\'|")?[\s\S]+(\1) I break the second regular expression down like this:[\S+[\s]? - At least one letter+ 0 or more spaces=[\s]*(\'|")? - The equal sign plus 0 or 1 opening quotations[s\S\]+(\1) - The contents of the attribute (1 or more characters) and the closing quotations (back referencing the quotation subpattern)Is this anywhere near correct? lolEDIT: I've been trying the aforementioned regular expression using this test data: href="www.google.com" title="Google" With the preg_grep() function...unfortunately, it returns the entire string as a single match, while I would like the expression to return each attribute as a match...What might I be doing incorrectly? Thanks in advance!
  10. Ok, I'm using the following regular expression to try and match HTML frame tags: <(frame|FRAME)[\s\S]*?/(\1)?> To break it down:<(frame|FRAME) Should match the opening tag[\s\S]*? Should match any number of letters or numbers inside the tag/(\1)?> Is a back reference to the first subpattern (frame|FRAME) plus the closing slash and bracket, and should match the closing tags /frame>, /FRAME>, or />This seems correct to me, but so far i'm not getting any matches for my test data...any ideas?
  11. You're probably right, but I'd rather set the server to parse XML and XSL files for PHP rather than parsing all files as such, simply for the sake of consistency (and security too) - telling the server to parse XML and XLS files should be relatively easy, at least it is for my Apache server.
  12. If so, then you should be able to do this without any problem. Say your file is xmlstyle.xslt. To modify the stylesheet based on a php request, you would have to do something like the following in the stylesheet itself: <xsl:for-each select="<?phpif($_GET['name'] == null) print '//pic[@category]">';else print $_GET['name'];?>"> The only problem here is that you have to propogate your change from your web page, to your xml file, to your xslt file. When you call your web page that contains the XML script that you want to modify, you would need to reference the file like this: xmlfile.xml?name='something' Make sure that your web server will look in .xml files for PHP code too, of course.Now, inside of your XML file, you would insert PHP code into the part of the file that references the XSL file: <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl<?PHPif($_GET['name'] != null) print '$_GET["name"]' . $_GET['name'];?>"?> I hope this isn't too confusing, lol.
  13. To be honest, I don't know alot about XSL, but I suppose it's possible to use PHP code to write SXL. However, make sure your web server knows to interpret SXL for PHP code or else it won't work.
  14. ThePsion5

    PHP Syntax

    Actually...if $total1 remains equal to zero, that last statement would print 'Your total is: ' because setting $total1 to zero is also 'false' and 'null', which won't print. You might want to do something like this:1. set $total1 = 02. calculate the prices3. check to see if $total1 is equal to 04. if it is, do this: $total1 = '0'That way, the zero will actually print, so if no purchases are made it will still say 'Your total is: 0' instead of nothing
  15. I can't really help you here, but you may want to take a look at some of the PHP-based content management systems around (my friend runs a PHP-based CMS at www.sallyvisual.com) and see how they do what they do.
  16. Try printing the mysql query before it' executed and checking to make sure the syntax is correct. Then, if it is, type the query into your server's mySQL command line (if possible) to see what results your coming up with, which may not be the right ones. Also make sure that the names of your post values are correct (including capitalization) because that's bogged my down many times.
  17. As I said before, you should include breaks and debugging output in your code to help you solve these problems. For example, debugging code like this: var_dump($_POST) can help you figure out if your variables are submitting correctly. I'd go through your code line by line and add echo & debugging statements - that's the best way to find out exactly what's happening.
  18. Hi guys,I'm trying to determine whether one can use SFTP with PHP's FTP functions, but so far my results are a bit inconclusive.I attempt to open the following connection on port 21, which isn't open - obviously, I get an error. However, when I attempt the same connection on port 22 (SFTP, if i'm not mistaken) with the appropriate username/password information, the PHP script simply runs continiously until the server shuts it down for surpassing the maximum execution. I feel like if PHP's ftp functions didn't support SFTP I'd get some kind of informative error message, but no luck. When setting the timeout value in ftp_connect(), the script does end after the specified amount of time, but what does that actually mean? Does PHP simply not support SFTP connections?P.S. I'm currently testing PHP version 4.4.2
  19. Have you tried adding breaks and debugging statements to your code to see at what point the script stops working properly? That might help.
  20. The problem is that results from a database in PHP are returned not as text but at a 'resource', a block of data representing the results you've recieved. To get the information out of it you need to use PHP's mysql functions, like mysql_num_rows() and mysql_fetch_array() and such. They're documented on PHP's website.
  21. Hi guys,I'm attempting to run a PHP script from the windows command line, but for some reason it's just not working...here's my command line script: php (directories)\test.php file1.txt file2.txt test.php calls a function that uses the command line arguments like so: function process($File1=null, $File2=null){ (handle GET, POST, other stuff) else if($argv[0] != null && $argv[1] != null) { $Current = $argv[1]; $Previous = $argv[2]; }} But whenever I try this, it won't work...according to PHP, the $argc and $argv variables aren't defined. I usually use PHP5 but I'm testing PHP4 compatibility...are command line arguments not supported in PHP4 or is there something else I'm doing wrong? Thanks in advance!
  22. I have an idea...like the topic says, it could be a really good idea or a very poor idea. I thought that since alot of people don't like having to install a database on their servers but want limited database functionality, that it might be possible to implement a pseudo-database using XML. But you can't just store the info in an XML file because then anyone could open it and read your possibly confidential information. So I thought of putting the XML into a PHP variable. Obviously there is one major obstacle for this:How do you update the PHP variable in a way that won't just revert back to the hard-coded values once the server is restarted? I thought about using file functions to write directly to the PHP file containing the variable, but I'm not sure if that would work. Feedback, anyone?
  23. All of my coding is Java style: function noSpacesButCaps() { ... }var $sameForVariables;constant LIKE_FINAL_VARS; It usually works very well for me, anyway.
  24. I should rename this topic to "I am stupid"Test Code: print htmlentities(preg_replace($tagRegExp, 'XXX', $currentTag)); My function code: $tagRegExp = '~(</?[^\W]*>)\1{1,1}~';$String = preg_replace($tagRegExp, '', $String);return $String; Anyone notice a slight inconsitency there? In conclusion - simple errors are embarassing.
  25. Hi,I'm using the regular expressions in PHP to remove duplicate XML tags in a document, and i'm trying to use the following regular expression to do so: (</?[^\W]*>)\1{1,1} Now, this works with a test string like this one: Which it turns into this: but the same regular expression fails when I use it to test this longer string: The regular expressions used to test them are identical in every way, does anyone have an idea of what might be going on? Thanks in advance!-Sean
×
×
  • Create New...