View Full Version : word and symbol replacement
TubeOfMommment
09-25-2009, 07:43 AM
:confused: hi .. i need help :)
postbit_display_complete
$find = "_";
$replace = " ";
$this->post['message'] = str_replace($find, $replace, $this->post['message']);
How to replace '_' only between text but not between [URL}{/URL} and [Img]{/Img[
--------------- Added 1253890729 at 1253890729 ---------------
any 1 can help ? :(
TubeOfMommment
09-30-2009, 07:38 AM
omg please guys help ....
TubeOfMommment
10-02-2009, 07:55 AM
bump
Lynne
10-02-2009, 02:20 PM
Just a post to let you know I have read your thread, but I have no idea how to do what you want.
Speysider
10-02-2009, 02:22 PM
Firstly, posting three times is not going to get anyone helping you on vB.org. It's really annoying.
Secondly, I have no idea what you want.
The Geek
10-02-2009, 04:00 PM
omg please guys help ....
I agree with these guys, however since I have done similar things before I thought I would throw in my 2 cents to help. I am sure there are better ways, but here is one approach:
From what I can see you will not be able to do what youre trying to do without some functions (unless you are god of regexp). First, substitute the reserved bits, secondly make the changes and last, change back your substitutions.
Here is some pseudo code to get you going. Its based on stuff I have done before, but uncluttered and untested.
function my_substitute($ref1, &$array)
{
static $i;
$i++;
$array[$i] = $ref1;
return "<<<@!$i!@>>>";
}
function my_unsubstitute($item, &$array)
{
return $array[$item];
}
function my_thang($find, $replace, &$text)
{
//This regexp should match [url] and [img] tags.
//We want to match them and call my_substitute on match,
$substitute = '%\\[[url|img]*([^\]]*)\](.*?)\[/[url|img]*\]%sime';
$subhandler = 'my_substitute(\'\1\', $subby)';
//this bit may not be needed, but it was a workaround for
//some glbalising issue. Just don't remember what issue that was
$subby = array();
$GLOBALS['subby'] = array();
$subby =& $GLOBALS['subby'];
//This replaces your url and img tags with placeholders
$text = preg_replace($substitute, $subhandler , $text);
//This bit is where you do whatever you were wanting to do
$text = preg_replace($find, $replace, $text);
//if there are subs, this bit replaces tokens back to what they were
if (sizeof($subby))
{
$text = preg_replace('/<<<@!([0-9]+)!@>>>/sme', 'my_unsubstitute(\'\\1\',$subby)', $text);
}
return $text;
}
Be nice next time :)
HTHs
TubeOfMommment
10-03-2009, 09:23 PM
I agree with these guys, however since I have done similar things before I thought I would throw in my 2 cents to help. I am sure there are better ways, but here is one approach:
From what I can see you will not be able to do what youre trying to do without some functions (unless you are god of regexp). First, substitute the reserved bits, secondly make the changes and last, change back your substitutions.
Here is some pseudo code to get you going. Its based on stuff I have done before, but uncluttered and untested.
function my_substitute($ref1, &$array)
{
static $i;
$i++;
$array[$i] = $ref1;
return "<<<@!$i!@>>>";
}
function my_unsubstitute($item, &$array)
{
return $array[$item];
}
function my_thang($find, $replace, &$text)
{
//This regexp should match [url] and [img] tags.
//We want to match them and call my_substitute on match,
$substitute = '%\\[[url|img]*([^\]]*)\](.*?)\[/[url|img]*\]%sime';
$subhandler = 'my_substitute(\'\1\', $subby)';
//this bit may not be needed, but it was a workaround for
//some glbalising issue. Just don't remember what issue that was
$subby = array();
$GLOBALS['subby'] = array();
$subby =& $GLOBALS['subby'];
//This replaces your url and img tags with placeholders
$text = preg_replace($substitute, $subhandler , $text);
//This bit is where you do whatever you were wanting to do
$text = preg_replace($find, $replace, $text);
//if there are subs, this bit replaces tokens back to what they were
if (sizeof($subby))
{
$text = preg_replace('/<<<@!([0-9]+)!@>>>/sme', 'my_unsubstitute(\'\\1\',$subby)', $text);
}
return $text;
}
Be nice next time :)
HTHs
ty ! sorry for bumps . wont happen again . ty for help !
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.