Jump to content

Archived

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

legohead6

Cutting letters out of a string!

Recommended Posts

how i cannot find a function! i want to cut these letters out then put them into another string in the order the were cut!

EDIT: by "these" i mean like an array of letters

or how to find all letters that were changed by str_replace...

Share this post


Link to post
Share on other sites
Your not being very clear. Maybe your looking for [url=http://php.net/substr]substr[/url](), but really... who knows.

Share this post


Link to post
Share on other sites
k i have an array or letters..(lets say $letters) and i have a sentence (say $text) I want to have it go through the sentance and find all the letters in the $letter array and remove them from the sentance. Then make them into there own array(called $removedletters)

Share this post


Link to post
Share on other sites
Probably better ways around, but....

[code=php:0]
<?php

  $letters = array('a','b','c','d');
  $text = "this is a big bad string";
  foreach($letters as $letter) {
    if (strpos($text,$letter)) {
      $removedletters[] = $letter;
      $text = str_replace($letter,"",$text);
    }
  }

  echo "the letters ".implode(" ",$removedletters)." were removed from '$text'";

?>
[/code]

Share this post


Link to post
Share on other sites

×

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.