• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

strreplace

Array (     [my_textarea] => HELLO )

str replace
only want 'HELLO'

 
0
rgb192
Asked:
rgb192
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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
 
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now