Jump to content

word replacements


EchoFool

Recommended Posts

Hey,

 

How would you apply a function to replace words which meet these conditions:

 

Not in the middle of a word for example... "IGH" changes to "TEST" but "HIGH" would not change.

Secondly the capital letters and non capital letters are not taken into account.

 

Currently i use:

 

<?php
$Message = str_replace('/rules', 'Please read the rules here <a href="rules.php">Game Rules</a>', $Message);
?>

 

How ever thers a number of problems here, if i want many things to be changed i would have to keep using lots of str_replace and updating $Message so wondering if theres an array method.

 

Secondly if '/rules' is typed like '/RULES' then it wont execute str_replace.

 

 

Link to comment
https://forums.phpfreaks.com/topic/207882-word-replacements/
Share on other sites

Hey,

 

How would you apply a function to replace words which meet these conditions:

 

Not in the middle of a word for example... "IGH" changes to "TEST" but "HIGH" would not change.

Secondly the capital letters and non capital letters are not taken into account.

 

Currently i use:

 

<?php
$Message = str_replace('/rules', 'Please read the rules here <a href="rules.php">Game Rules</a>', $Message);
?>

 

How ever thers a number of problems here, if i want many things to be changed i would have to keep using lots of str_replace and updating $Message so wondering if theres an array method.

 

Secondly if '/rules' is typed like '/RULES' then it wont execute str_replace.

 

Did you read the manual for str_replace?  It may accept arrays for search and replace parameters.  So might str_ireplace() which is case-insensitive.

Link to comment
https://forums.phpfreaks.com/topic/207882-word-replacements/#findComment-1086733
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.