Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have field in my table with data: DE;RO;US;
Question is how extract data in array as:
$array = array('DE', 'RO', 'US');
use explode function.
Like this :
$string = 'DE;RO;US;';
$arr = explode(';',$string);
You can use the function explode() here.
$array = explode(';', $data);
The variable data is the result of you database query.
http://us1.php.net/manual/en/function.explode.php
BTW: Your way to save things in the database is not good. Have a look at database normalization.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is the array: http://www.stylechica.de/array.rtf (I can't copy it here)
I need to sum up ["PriceInformation"]["PriceInformation"]["PriceDetails"]["Price"] and allready tryed all kind of stuff like
foreach ($output["PriceInformation"]["PriceDetails"]["Price"] as $product)
echo array_sum($product);
but it just won't work. Any ideas?
Because $product refers to each iteration of $output["PriceInformation"]["PriceDetails"]["Price"], you can't sum the entire array like this. The best way to do it would be to add it to a variable as you go:
$your_sum = 0;
foreach($output as $value) {
$your_sum += $value['PriceInformation']['PriceDetails']['Price'];
}
echo 'Sum: ' . $your_sum;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
If I have an array with identifiers like this "name" => "Manoel", "age" => 45 then how can I turn them into individual variables without having to know each identifier in the array? is it possible?
Can I do that inside a class to create new properties?
Thanks.
Try this:
<?php
$Wales = 'Swansea \n';
print $Wales;
$capitalcities['England'] = 'London';
$capitalcities['Scotland'] = 'Edinburgh';
$capitalcities['Wales'] = 'Cardiff';
extract($capitalcities);
print $Wales;
?>
The result you should see in your browser is:
Swansea
Cardiff
And yes, if you do this inside an object you may have those variables as properties in execution time.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I get the data from database and I want to sort hotel_name in alphabetical order. How can I do it using php's sort function or any other method ?
foreach($selData as $row)
{
$name=$row['hotel_name'];
$distance_colombo=$row['distance_colombo'];
$distance_airport=$row['distance_airport'];
$description=$row['description'];
$activities=$row['activities'];
$str=(explode(',',$activities));
print_r($str);
}
There's no need to use sort() here. Just use ORDER BY in your SQL query.
Example:
SELECT * FROM table_name ORDER BY hotel_name
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I suck at regexp but i'd like to just do a simple filter where / is replaced with 1, " is replaced with 2 and < is replaced with 3.
I'd appreciate an example where the syntax would be straight forward, i'd like to run this filter through the input of a get variable provided by the user. A syntax like:
replace(/,1)
replace(",2)
replace(<,3)
.
Thanks.
I really don't see the need for regex here.. You can just use str_replace
E.g.
str_replace('/', '1', $_GET['var']);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have text like this Too early to post? http://www.somewebsite.com/article/226973 I want to parse the hyperlinks in the text and make the text look like so Too early to post? http://www.entrepreneur.com/article/226973 I want to do this but I have no idea where to start from or what regexp to use.
$s = 'Too early to post? https://www.somewebsite.com/article/226973';
$parsed = preg_replace('#(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)#', '$1', $s);
echo $parsed;