Jump to content

str_replace()


Shadow Hatake

Recommended Posts

Okay I have a problem. I want to echo the results of a str_replace() but when I put echo infront of it it goes into a huge loop. Here's my code:

[code]<?php

$test = "a b";

$letters = array('a', 'b');
$replace = array('t455', '5gr4');

str_replace($letters, $replace, $test);

?>[/code]

So how should I go about doing this?
Link to comment
Share on other sites

You could also put it on a function, so it will be easier to use.
[code]<?php

function replacewords($text) {

$letters = array('a', 'b');
$replace = array('t455', '5gr4');

$text = str_replace($letters, $replace, $text);
return $text;
}

echo replacewords("a b");

?>[/code]
Link to comment
Share on other sites

Odd. Would it make a difference if I was using more letters?

This is the whole code I'm using.
[code]
<?php

$test = "a";

$letters = array( 'a',
  'b',
  'c',
  'd',
  'e',
  'f',
  'g',
  'h',
  'i',
  'j',
  'k',
  'l',
  'm',
  'n',
  'o',
  'p',
  'q',
  'r',
  's',
  't',
  'u',
  'v',
  'w',
  'x',
  'y',
  'z');
 
$replace = array( 'b5fc',
  'c8hd',
      'd8re',
      'ej9f',
      'f8jg',
      'g8ph',
      'hd7i',
      'iokj',
      'ji8k',
      'kh0l',
      'lbhm',
      'm87n',
      'nuvo',
      'ohvp',
      'p7yq',
      'qjhr',
      'ribs',
      'soit',
      't9nu',
      'ud6v',
      'v89w',
      'w9sx',
      'x8sy',
      'y9dz',
      'z8ha',
      'a9jb');

echo str_replace($letters, $replace, $test);

?>[/code]

http://www.infected-designs.com/replace.php
Link to comment
Share on other sites

<?

//This is erigi replace with no array.

$a="i dont wont this text";

$b ="please print me!";

$replace=eregi_replace($a,"",$b);

echo $replace;

?>

<?

//This is eregi with array

$a=array("i dont wont this text");

$b=array("please print me!");

$replace=eregi_replace($a[0],"",$b[0]);

echo $replace;

?>


<?

//This is str_replace with no array.

$a="i dont wont this text";

$b ="please print me!";

$replace=str_replace($a,"",$b);

echo $replace;

?>

<?

//This is str_replace with array

$a=array("i dont wont this text");

$b=array("please print me!");

$replace=str_replace($a[0],"",$b[0]);

echo $replace;

?>
Link to comment
Share on other sites

<?php



$letters = array( 'a',
  'b',
  'c',
  'd',
  'e',
  'f',
  'g',
  'h',
  'i',
  'j',
  'k',
  'l',
  'm',
  'n',
  'o',
  'p',
  'q',
  'r',
  's',
  't',
  'u',
  'v',
  'w',
  'x',
  'y',
  'z');
 
$replace = array( 'b5fc',
  'm8hd',
      'd8re',
      'ej9f',
      'f8jg',
      'g8ph',
      'hd7i',
      'iokj',
      'ji8k',
      'kh0l',
      'lbhm',
      'm87n',
      'nuvo',
      'ohvp',
      'p7yq',
      'qjhr',
      'ribs',
      'soit',
      't9nu',
      'ud6v',
      'v89w',
      'w9sx',
      'x8sy',
      'y9dz',
      'z8ha',
      'a9jb');


echo str_replace($letters[2]," ", $replace[1]);


hope this helps ok.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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