Jump to content

Vizor

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Everything posted by Vizor

  1. It's not the select tag that takes the value option it's the options themselves. For example it should be: <select name="select_box"> <option value="1">1</option> <option value="2">2</option> </select> One way of getting the select box to show the selected option would be to turn the whole select part into a string and then use str_replace to add a selected="selected" attribute. <?php $select = '<select name="select_box"> <option value="1">1</option> <option value="2">2</option> </select>'; $selected_value = '2'; $select = str_replace($selected_value . '">', $selected_value . '" selected="selected">', $select); echo $select; ?>
  2. How is the date column set up? is it a timestamp value? if it is then you can just do SELECT * FROM articles ORDER BY date DESC LIMIT 5;
  3. Third result from google. http://www.tizag.com/javascriptT/javascriptconfirm.php Javascript is client side and PHP is server side, you can't mix the two. You could use javascript to confirm whether a user wants to do something then if they do redirect to a PHP page that does whatever they wanted.
  4. As far as I know you can't but you can with javascript so you could check with javascript whether it's there and redirect to different pages accordingly.
  5. Sorry, I didn't read your post properly. well, one thing you could do is: <?php $text = '<p>This is some text. <p>Another paragraph</p> Some more text</p>'; if(substr($text, 0,3) == '<p>' && substr($text, -4) == '</p>') { $text = substr($text, 3); $text = substr($text, 0, -4); } echo $text; ?>
  6. Post the error message...
  7. If you print_r($_POST); you will see it goes on name=>value for it's information. ID is a HTML attribute that can be used by other languages for example javascript.
  8. You could use strip_tags() and then add <p> and </p> to the beginning and end of your text.
  9. You need to encode < and > or at least handle them in some way else your script is ripe for exploitation, if you want the user to see < and > in the page then they must be encoded to < and > respectively, if you want to create hyperlinks then they are left as < and > in the source.
  10. Vizor

    need help

    <!-- blah --> comments things in HTML not PHP. To comment in php you can use // or # for a line comment or /* lots of lines */ for a block of code.
  11. Um, the die() function will stop all script execution and in this case output mysql_error(). Yes you read the error right you have a < that shouldn't be there or is in the wrong place.
  12. A common problem with header() saying that output has already started is that you have a space at the end of your PHP block, e.g. after ?> just highlight everything in a text editor and look for extra spaces as these count as output.
  13. Vizor

    crontab help me

    @DarkWater: So are you. It depends whether or not you add #! /usr/bin/php to the start of your script and then chmod +x it; if you do that then you don't need to specify that it's to be run through the php parser.
  14. Try using file_exists() instead of is_dir() also it might be a problem with whatever code is in your else block unless you're having problems with that basic script that you posted.
  15. Vizor

    crontab help me

    Crontab has the format m h dom mon dow command so if you wanted a script to execute every tuesday you would put in your crontab * * * * 2 /home/bin/script.php I'm sure you could work the rest out for yourself.
  16. This would read every 8 bytes from 1024 bytes into the file. <?php $fp = fopen('file.txt', "r"); $offset = 1024; while(!feof($fp)) { echo fgets($fp, $offset); $offset += 8; } fclose($fp); ?>
  17. Well if you are exploding that last row then just use count() to get how many items there are in your array.
  18. Just get into a habit of tabbing correctly.
  19. To send HTML emails you need to set the content-type headers. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  20. You can't include remote PHP scripts, if you try that it will only return what the script generated. The only thing you can do is store a local copy of the script you want and include that.
  21. PHP has a PDF extension. http://uk2.php.net/pdf
  22. Fine here it is, the whole thing done for you :/ <?php $string = "This is the sample string. <a href=#>click here</a>. Other Rome"; $pattern = '^\<a\ href=(.+?)\</a\>^'; $result = preg_match($pattern, $string, $matches); print_r($matches); ?> And yes that does work.
  23. Regular expressions, look up preg_match(). also with a hyperlink at the <a> tag it ends in </a> not [/url] that's just bbcode. You'll want something like <?php $pattern = '<a\ href=(.+?)</a>'; //this is the regular expression, probably doesn't work. $haystack = $string; //this is your database data. $results = preg_match($pattern, $haystack, $matches); //$matches is an array of matches found by preg_match. print_r($matches); ?>
  24. Do you mean as in filter for bad chars etc? Try urlencode().
  25. It's hard to check for this sort of thing unless you were to actually compare it with every word in the dictionary, there is a php extension that allows you to check the percentage probability of a word being random. What is the input field for? If it's something like an email it could be checked for certain things like @.
×
×
  • 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.