Current location: Hot Scripts Forums » Programming Languages » PHP » a problem while using replace functions.. please HELP


a problem while using replace functions.. please HELP

Reply
  #1 (permalink)  
Old 07-08-06, 04:50 PM
basselkh basselkh is offline
New Member
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
a problem while using replace functions.. please HELP

Hi
this is my first post
I hope finaly some one will answer my question

I'm writing a code that replace some chars with others

the question is: can I give ( str_replace ) some thing to tell it to ignore some differences betwen the two strings, I meen something like special chars..??

I found a function which ignores differences in spacing (like tab, carriage return, line feed, etc.)

But I need to ignore more differences such as ( special cahrs I use, they are almost non english letters )

please some one tell me how to do that or how to make the function bellow Ignore and chars I want

Thanks a lot every body
PHP Code:

<?php 

function str_rep($srcfor,$chwith,$mystr

   if(
strlen($mystr) == 0
       return 
""

   
$tok  strtok($srcfor," \n\t\r"); 
   
$strsrc = array(); 
   
$idxsrc = array(); 
   
$i 0
   while(
$tok
   { 
       
$strsrc[$i] = $tok
       
$pos strpos($srcfor,$tok); 
       
$idxsrc[$i]=$pos
       
$tok strtok(" \n\r\t"); 
       
$i++; 
   } 

   
$tok2  strtok($mystr," \n\t\r"); 
   
$str = array(); 
   
$idx = array(); 
   
$j 0

   while(
$tok2
   { 
       
$str[$j] = $tok2
       
$pos strpos($mystr,$tok2); 
       
$idx[$j]=$pos
       
$tok2 strtok(" \n\r\t"); 
       
$j++; 
   } 

   for(
$m=0;$m<$j;$m++) 
   { 
       if(
strcasecmp($strsrc[0] , $str[$m]) == 0
       { 
           for(
$l=1;$l<$i;$l++) 
           { 
               if(
strcasecmp($strsrc[$l],$str[$m+$l]) != 0
                   break; 
           } 
           
$l--; 
           if((
$l+1) == $i
           { 

               
$new_str=substr($mystr,0,$idx[$m]); 
               
$new_str .= $chwith

               
$index $idx[$m+$l]+strlen($str[$l+$m]); 
               
$len strlen($mystr)-$index

               if(
$len 0
                   
$new_str .= str_rep($srcfor,$chwith,substr($mystr,$index,$len)); 

               return 
$new_str
               break; 
           } 

       } 
   } 

   return 
$mystr

?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with calling several functions perleo JavaScript 2 12-17-05 11:00 PM
Wanted to replace special characters in MS Access using VB, but more than 1 character cebuy Visual Basic 3 12-04-05 05:30 PM
Wierd Problem With Functions. . . Spreegem PHP 8 02-14-05 10:46 AM
Count problem kasic ASP.NET 1 10-20-04 12:23 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM


All times are GMT -5. The time now is 07:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.