coolguydudeman
-
Posts
7 -
Joined
-
Last visited
Never
Posts posted by coolguydudeman
-
-
$convertChar = "*";
it would be replaced with, *****.
-
Well "apple" would not be replaced with anything from the above code. But i was just using the fruit names instead of the actual swear words
-
I am trying to figure out a way of filtering certain words from a string using str_replace - However i would like to replace the words with something showing the correct length of the word.
So far I have got:
<?php $input = "Oranges, apples, and pears are all types of fruit!"; $words = array("oranges","apples","pears"); function convertType($x) { $maskWords = array(); $convertChar = "*"; for ($i = 0; $i < strlen($x); $i++) { array_push($maskWords, $convertChar); } $convertString = implode(".", $maskWords); $stripString = str_replace(".", "", $convertString); return $stripString; } for ($i = 0; $i < count($words); $i++) { $input = str_ireplace($words[$i], convertType($words[$i]), $input); } print $input; ?>
As I am fairly new to PHP I am not sure if this is the most effiicent way of doing this so I was hoping somebody could provide some input for me. For instance is there a function to convert the array into a full-length string without using a delimiter?
Thanks!
-
Thanks for that one mjdamato thats exactly what i was looking for! I appreciate the time you've taken to write that up for me.
-
Thanks for the reply mjdamato - I apologise for the bad explanation, I would like PHP to automatically create a number sequence starting at 1 and finishing at 30 with a step order of 11, 7, 11 without storing any information in arrays, I was thinking a for loop, but my attempts havent proven sucessful.
-
i am trying to make a range of numbers which have a step of 11 then 7 then 11 which can then be compared. the result im after is 1, 12, 19, 30. Is there a way i could do this without storing the sets in an array and looping though them? Any help would be greatly appreciated, thanks.
str_replace with correct length of chars
in PHP Coding Help
Posted
Thanks allot!