Jump to content

Nicklas

Members
  • Posts

    111
  • Joined

  • Last visited

    Never

Everything posted by Nicklas

  1. Yeah, I know, but for some reason, the expression falls apart if I do it that way, if I put the optional [b]s[/b] in a subpattern, it works. Anyways, here´s a small update, the previous regexp removed everything as it should, but left the [b]www[/b] untouched. this has now been fixed. [code=php:0]$string = "Here's a ftp://mysite.com - ftp.mysite.com string and https://mysite.com with a link to www.somesite.com and to http://www.anothersite.com bla bla. Yet another link to http://mysite.com/somedir/mysite.html"; echo preg_replace('/((http(s)?:\/\/|ftp(:\/\/|\.)))?(www\.)?/is', '', $string);[/code]
  2. Here´s one that takes care of [color=blue]ftp://[/color], [color=blue]ftp.[/color], [color=blue]http://[/color], [color=blue]https://[/color] and [color=blue]www[/color] [code=php:0]$string = "Here´s a ftp://mysite.com - ftp.mysite.com string and https://mysite.com with a link to www.somesite.com and to http://www.anothersite.com bla bla. Yet another link to http://mysite.com/somedir/mysite.html"; echo preg_replace('/(http(s)?:\/\/|ftp(:\/\/|\.))(www\.)?(.*?[^\s])/is', '\\5', $string);[/code]
  3. [code=php:0]<?php $string = 'bla bla bla ëíñçíàéö bla bla ñç...'; $change = array('ë', 'í', 'ñ', 'ç', 'í', 'à', 'é', 'ö'); $tothis = array('a', 'i', 'n', 'c', 'i', 'a', 'e', 'o'); echo str_replace($change, $tothis, $string); ?>[/code]
  4. [code=php:0]preg_match_all('/(?<=<\/b>).*?(?=<br( \/)?>)/is', $string, $matches); print_r($matches);[/code]
  5. You want to match the text in bold?
  6. Try something like this. This regexp removes the HTTP:// and the WWW. if it´s present in the link ex: [code=php:0]$string = "Here´s a string with a link to www.somesite.com bla bla"; echo preg_replace('/(http:\/\/)?www\.([-a-z0-9_][-a-z0-9_\.]+\.[a-z]{2,4}(\/[-a-z0-9_\.%&+\/=&]+)?)/is', '\\2', $string);[/code]
  7. You can try my Audio CAPTCHA and see how it goes: http://www.nswardh.com/shout
  8. you have to write: [code=php:0]echo $_SESSION['empcode'];[/code]
  9. [code]try something like this: [code=php:0]$string = "My email is joe@yahoo.com - please send it there"; echo preg_replace('/([-a-z0-9_][-a-z0-9_\.]+)@([-a-z0-9_][-a-z0-9_\.]+)\.([a-z]{2,4})/ise', 'str_repeat("x", strlen("\\1")) . "@" . str_repeat("x", strlen("\\2")) . "." . str_repeat("x", strlen("\\3"))', $string); [/code]
  10. with "filter", you mean remove them? You could place all the letters you wanna remove in an array and then use str_ireplace() (if you use PHP 5) to delete them. ex: [color=blue]<?php $string = 'bla bla bla ëíñçíàéö bla bla ñç...'; $chars = array('ë', 'í', 'ñ', 'ç', 'í', 'à', 'é', 'ö'); echo str_ireplace($chars, '', $string); ?>[/color]
  11. Or [code=php:0]preg_replace('/(<img.*?alt=).*?>/is', '\\1y>', $string);[/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.