Hi there,
I have two objectives:
1.I am trying to write the best code preferably a function for ignoring a particular word/strings from a given text
for Eg.:
Input: Why are you going there
say I have called the method to Ignore "are" I'll get output as
Output: Why you going there?
2. I want to check wether a particular pattern is present in the text or not?
I may need both of above at the same time or any one of them in single.
If possible write a code for me.
String Manipulation
Moderator: General Moderators
-
kapil1089theking
- Forum Commoner
- Posts: 46
- Joined: Wed May 28, 2008 1:51 pm
- Location: Kolkata, India
- Contact:
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: String Manipulation
HAHAkapil1089theking wrote:If possible write a code for me.
Re: String Manipulation
Code: Select all
<?php
$blacklist = array("are", "is");
$text = "Why are you going there";
$words = explode(" ", $text);
$output = array();
foreach($words as $word)
{
if(!in_array($word, $blacklist)) $output[] = $word;
}
$output = implode(" ", $output);
?>
Re: String Manipulation
str_replace(), preg_match() are your friends.