strreplace

Array (     [my_textarea] => HELLO )

str replace
only want 'HELLO'

 
LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

john-formbyCommented:
Do you mean echoing out the value to the page?

If so, just echo like this:

<?php
$myarray = Array(my_textarea => 'HELLO');
echo $myarray['my_textarea'];
?>

Hope this helps,

John
0
rgb192Author Commented:
that is not working

is there a way to do it with a str_replace
0
john-formbyCommented:
What you have there is not a string, but the result of print_r I am guessing?

If that is the case, you cannot simply use str_replace because it is not a string.

Please post your code and I will assist further
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

rgb192Author Commented:
it is not the result of print_r


$variable='Array (     [my_textarea] => HELLO )';
echo $varible



0
Rok-KraljCommented:

$variable='Array (     [my_textarea] => HELLO )';
echo str_replace(array('Array (     [my_textarea] => ', ' )'), '', $varible)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
john-formbyCommented:
Hi,

Please try the following code.

Hope this helps,

John
$variable='Array (     [my_textarea] => HELLO )';
$variable1 = substr($variable, 0, (stripos($variable, "=>")+2));
$variable = str_replace(' )','',str_replace($variable1, '', $variable));
echo $variable;

Open in new window

0
derdiuszCommented:
Try to use eval() method:

$data = 'Array (     my_textarea => HELLO )';

eval("\$arr = $data;"); // remember to use ";" at the end (after $data)

And from now in variable $arr you've got your array. If want your "HELLO" use:

echo $arr['my_textarea'];


Greetings!
0
Rok-KraljCommented:
Yes, along with a bunch of errors.
0
derdiuszCommented:
Only twice Noticy ;)

but when you add:

$data = 'Array (     [my_textarea] => HELLO )';
$data = strreplace(array('[', ']'), array("['", "']"), $data);

it be nicer, a little ;)
0
rgb192Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.