Okay, I just want to print the contents of an array then I want to replace the the contents of the string of the array then replace the them with another name...plase someone help me... I don't really get what to do to it, can someone show me how to do this right and how to use preg_replace? Everywhere I look up how to do it they have really weird symbols in it:
Even in my code, I just sorta put those things in it because its what everyone else does >.> even on the php manual website...I think I hate PHP
<!doctype html>
<html lang="en">
<head>
<title>test6</title>
</head>
<body>
<!-- Insert your content here -->
<?php
class myArrayContainer{
function myArrayFunction(){
return $myArray = array(
"Name" => "John",
"LastName" => "Smith",
);
}
}
$myShitz = new myArrayContainer();
$myShit = $myShitz->myArrayFunction();
$myShitClass = new myArrayClass($myShit);
//print_r($myShit);
class myArrayClass {
function __construct($myArray){
echo ("Printing my Array as Recieved");
echo ("</br>");
print_r(array_values($myArray));
$myProcessClass = new myProcess($myArray);
}
}
class myProcess {
function __construct($sameArray){
$mySentence = serialize($sameArray);
print_r($mySentence);
$placements = array ("John" => "Jose", "Smith" => "Tobar");
preg_replace("/:(\w+)/e", $placements[$1], $mySentence);
}
}
?>
</body>
</html>
print_r
in myArrayClass::__construct
should print "John" and "Smith" (no keys). Doesn't it?$mySentence
is a string, so no print_r
needed.preg_replace
result...json_encode() -> preg_replace() -> json_decode()
:.
$mySentence = json_encode($sameArray); // assoc array in
$mySentence = preg_replace('/a/', 'b', $mySentence);
$otherArray = json_decode($mySentence, true); // assoc array out
Be careful though. Even json can be messed up if you replace it like that.