Jump to content

thebadbad

Members
  • Posts

    1,613
  • Joined

  • Last visited

Everything posted by thebadbad

  1. You're relying on the register_globals setting being on, which is bad! Have a read about it here: http://www.php.net/manual/en/security.globals.php. In this case you need to use $_POST['text'] instead of $text, or alternatively if (isset($_POST['text'][0])) to check that the variable is set and not an empty string.
  2. ~^warrior [a-z]+ [0-9]{1,3}$~im The m modifier makes ^ and $ match at the start of the string and after a newline, and at the end of the string and before a newline, respectively.
  3. Faster to use explode(): <?php $str = '{options=opt_1|opt_2|opt_3|opt_n}'; preg_match('~{options=([^}]+)}~i', $str, $match); $options = explode('|', $match[1]); echo '<pre>' . print_r($options, true) . '</pre>'; ?>
  4. Is your sample HTML the full string or is it part of a bigger?
  5. You'll find the answer here: http://www.phpfreaks.com/forums/index.php/topic,268055.0.html
  6. ~^.*?[.?](?![^<]*?>)~s Explanation here: http://www.phpfreaks.com/forums/index.php/topic,257050.msg1209420.html#msg1209420
  7. No, the value of the onclick attribute is run as javascript. And just so you know, <script language="javascript"> is deprecated in favor of <script type="text/javascript">
  8. Pay attention to the quotes: <?php echo '<a href="#" onclick="return confirm(\'Are you sure?\')">link</a>'; ?> I simply surrounded the HTML with single quotes, and escaped the single quotes within it.
  9. It doesn't work that way. Have a read about variable scope here: http://php.net/manual/en/language.variables.scope.php
  10. A question mark following a quantifier makes it lazy, meaning that it will match as little as possible. There's a longer explanation and some examples in this thread: http://www.phpfreaks.com/forums/index.php/topic,236933.msg1104789.html#msg1104789
  11. Garethp, <p[^>]+> will not match <p>, you would have to use an asterisk instead of the plus. And you have to make your second quantifier lazy, else it'll match to the last closing tag in the source. Lastly, you misplaced the pattern modifier This'll do: ~<p\b[^>]*>(.*?)</p>~is I added the word boundary \b so that it doesn't wrongfully match tags like pre and param. Important in case those tags appear in the source.
  12. Add a question mark after the plus to make it ungreedy.
  13. Just loop through the array: <?php foreach ($ten as $url) { echo '<img src="' . $url . '" alt="" />' . "\n"; } ?>
  14. I'm afraid move_uploaded_file() and similar functions don't support Unicode filenames.
  15. <?php $lines = file('filename.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); shuffle($lines); $ten = array_slice($lines, 0, 10); echo '<pre>' . print_r($ten, true) . '</pre>'; ?>
  16. Did you store the MySQL link identifier returned by mysql_connect() in $connection prior to running the queries? A last thing to try could be to set the header: header('Content-type: text/html; charset=utf-8'); If it still doesn't work, I don't know what to tell you. It should work if you do the things right that you and I have outlined.
  17. Have a look at imageantialias(). @bossman We're talking PHP GD.
  18. Only run mysql_real_escape_string() (and strip_tags(), if you want to remove potential tags) on a string before inserting it to the database. Then when you display the data on your pages, run it through htmlentities() or htmlspecialchars() to prevent the data from being interpreted as (X)HTML. And didn't you notice your function applies htmlspecialchars() twice?
  19. You also need to set NAMES and CHARACTER SET to UTF-8. Run these queries just after you've connected to your database: mysql_query("SET NAMES 'utf8'", $connection); mysql_query("SET CHARACTER SET 'utf8'", $connection);
  20. You're right, that's not how it's supposed to work, and it's not how it works on my servers (PHP 5.2.3 @ Apache; PHP 5.2.6 @ Apache). Either it's a bug, or you're doing it wrong somehow. Have you tried to copy and paste the URL to the address bar, and then see what print_r() says?
  21. I can recommend http://www.regular-expressions.info/.
  22. Try this: <?php //$str contains the source code preg_match('~<img\b[^>]+src="([^"]*pgallery.jpg)"~i', $str, $match); echo $match[1]; ?> It searches for the first img tag, where the value of the src attribute ends in pgallery.jpg.
  23. Or the array is multidimensional. And if one of the array values contains a comma, you won't end up with the same array as you started with. You can use rawurlencode(serialize($clean)) to convert the array to an (escaped) string, and then unserialize(rawurldecode($_GET['d'])) to convert it back to an array on your second page.
  24. You can grab the URLs with regex: <?php $str = "html here<a class='link' href='http://www.site.com/?q=6J4W2G4fASI'>html here html here<a class='link' href='http://www.site.com/?q=637yfuhqelhe'>html here html here<a class='link' href='http://www.site.com/?q=hilghye8oyhi'>html here"; preg_match_all('~<a\b[^>]+href\s?=\s?[\'"](.*?)[\'"]~is', $str, $matches); echo '<pre>' . print_r($matches[1], true) . '</pre>'; ?> Note that $matches[1] will be an array of the URLs. Or alternatively use PHP DOM: <?php $urls = array(); $str = "html here<a class='link' href='http://www.site.com/?q=6J4W2G4fASI'>html here html here<a class='link' href='http://www.site.com/?q=637yfuhqelhe'>html here html here<a class='link' href='http://www.site.com/?q=hilghye8oyhi'>html here"; $dom = new DOMDocument(); $dom->loadHTML($str); $tags = $dom->getElementsByTagName('a'); foreach ($tags as $tag) { $urls[] = $tag->getAttribute('href'); } echo '<pre>' . print_r($urls, true) . '</pre>'; ?>
  25. You need to store what's returned by your function in $input: $input = get_user_input(200);
×
×
  • 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.