error2013
asked on
PHP Code Modification
Hi all,
I have the following code which I need modifying.
The code works great but the search replace words are not working properly in multiple lines:
For example:
Can anyone help please?
I have the following code which I need modifying.
$article = 'Perfume is a mixture of fragrant word1 and aroma complexes, which can be applied to the human body, animals, word2, objects, and living spaces in order to give off a pleasant word3.';
//words to be replaced
$words = '{word1|word2|word3|word4|word5}';
$words = explode("|", substr($words,1,-1));
//replacement words
$newWords = $words;
//randomise the new words
shuffle($newWords);
//perform the replacement
$newArticle = str_replace($words, $newWords, $article);
echo $newArticle;
The code works great but the search replace words are not working properly in multiple lines:
For example:
$words = '
{word1|word2|word3|word4|word5}
{word66|word23|word32|word47|word56}
{word13|word22|word31|word46|word55}
';
Can anyone help please?
ASKER
I'm getting this error:
Warning: shuffle() expects parameter 1 to be array, string given in /home4/public_html/index.p hp on line
Warning: shuffle() expects parameter 1 to be array, string given in /home4/public_html/index.p
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please correct me if I'm wrong, but this looks like an attempt to randomize some text so that it carries the same meaning but looks different to search engines. The degree to which you control the programming and data will be useful in getting you the best solution. Are you stuck with the format of the search and replace words' strings? If not, I can suggest a little bit different design that would make things easier. If you write the words in the form of arrays as shown here, the process of editing and the programming to use the arrays is somewhat easier and less prone to typographical errors.
http://www.laprbass.com/RAY_temp_error2013.php
http://www.laprbass.com/RAY_temp_error2013.php
<?php // RAY_temp_error2013.php
error_reporting(E_ALL);
echo '<pre>';
$article = 'Perfume is a mixture of fragrant word1 and aroma complexes, which can be applied to the human body, animals, word2, objects, and living spaces in order to give off a pleasant word3.';
echo PHP_EOL . $article;
// WORDS TO BE REPLACED IN THE FORM OF AN ARRAY
$words = array
( 'word1'
, 'word2'
, 'word3'
, 'word4'
, 'word5'
, 'word66'
, 'word23'
, 'word32'
, 'word47'
, 'word56'
, 'word13'
, 'word22'
, 'word31'
, 'word46'
, 'word55'
)
;
//replacement words
$newWords = $words;
//randomise the new words
shuffle($newWords);
//perform the replacement
$newArticle = str_replace($words, $newWords, $article);
echo PHP_EOL . $newArticle;
HTH, ~Ray
Open in new window