Jump to content

Nicklas

Members
  • Posts

    111
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://www.nswardh.com

Profile Information

  • Gender
    Male
  • Location
    www.nswardh.com

Nicklas's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. you dont need strlen, it´s enough with: [code=php:0]substr($postcode, 0, -3);[/code]
  2. The [b]e[b] modifier is missing in preg_replace() change to this: [code=php:0]echo preg_replace("/$searchterm/ise", 'highlight("\\0")',  $result);[/code]
  3. [quote]why you call the highlight function with highlight("\\0")?[/quote] \\0 is a backreference and holds the matched keyword(s) [quote]Because now the keywords in the result instead of highlight they get replaced with "highlight ("keywords")" string!!!![/quote] Show me your code.
  4. the preg_replace call the function highlight() and takes the match, split it and then surround each word with a <span> tag. Then the string is put back together via the $tmp variable and return it to preg_replace().
  5. do something like this if you want to highlight them individually: [CODE]<?php function highlight($str) { $tmp = ''; foreach(explode(' ', $str) as $word) $tmp .= "<span style=\"background-color:yellow\">$word</span> "; return trim($tmp); } $query = "test query"; $string = "hello there, this is a test query"; echo preg_replace("/$query/ise", 'highlight("\\0")', $string); ?>[/CODE]
  6. http://www.phpfreaks.com/forums/index.php/topic,115226.msg469086.html#msg469086
  7. better to use [ and  ], { and } will be out of use in PHP6
  8. [CODE]<?php $str = 'hello http://website1.com some word http://website2.com whatever else'; $spam = substr_count(strtolower($str), 'http://') - 1; echo $spam; // Result: 1 ?>[/CODE]
  9. [code=php:0]echo preg_replace('/(""").*?\1/s', '<span style="color: blue">\\0</span>', $text);[/code]
  10. correct me if i'm wrong, but if I remember correctly, the maximum allowed filesize is 2Mb. If your files go beond that, they wont be uploaded unless you edit your php.ini to allow bigger filesizes.
  11. How do you store this list? database, textfile... ?
  12. Here´s another way of displaying the first 10 words: [code=php:0]<?php $text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; list($words) = explode(' |', preg_replace('/(.*?\s+){10}/s', '\\0|', $text)); echo $words; ?>[/code]
  13. I would use [url=http://www.php.net/preg_split]preg_split()[/url] to do the job. ex [code=php:0]list($artist, $title) = preg_split('/ - | \(/', $info);[/code] Then I just need to do something like this to loop thru my mp3 files and get the artist + title at the same time: [hr] [code=php:0]foreach(glob("some_dir/*.mp3") as $info) { list($artist, $title) = preg_split('/ - | \(/', $info); // Do what you want here... }[/code][hr]
  14. Take a look at [url=http://www.php.net/strtotime]strtotime()[/url] ex [CODE]<?php $date = '2007-12-01'; echo date("m-d-Y", strtotime($date)); ?>[/CODE]
  15. You could do something like this: [code=php:0]$str = 'bla bla bla...'; // select all <font> tags from the $str string preg_match_all('/(<font[^>]*>)/is', $str, $match); $match = $match[0]; // remove all tags with the size option foreach($match as $key => $tag) { if (preg_match('/size=("|\')?(\d+)?("|\')?/is', $tag)) unset($match[$key]); } // present all matched <font> tags print_r($match);[/code]
×
×
  • 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.