Concatenate URL and display the image in the URL PHP [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
my question is how do you concatenate para1 and para2, and displays the image that is in the url for each of the data in the web1 array in PHP?
Here is an example of what I wanted.
From url1: www.example.com/jferf0923i092eijodsojs
Please keep in mind that these urls are just an example of what I want to achieve.
{"Web 1": {
"url1": {
"para1": "www.example.com",
"para2": /jferf0923i092eijodsojs,
},
"url2": {
"para1": "www.example.com",
"para2": asjdoisadj829332oijd,
},
"url3": {
"para1": "www.example.com",
"para2": assasdijoj21389445,
}
}}
I appreciate your help! Cheers

I assume this is roughly what you are looking for, at least it should give you a start:
<?php
$catalog = [
"Web 1" => [
"url1" => [
"para1" => "www.example.com",
"para2" => "jferf0923i092eijodsojs",
],
"url2" => [
"para1" => "www.example.com",
"para2" => "asjdoisadj829332oijd",
],
"url3" => [
"para1" => "www.example.com",
"para2" => "assasdijoj21389445",
]
]
];
foreach ($catalog as $entry) {
foreach ($entry as $url) {
$imageUrl = sprintf('https://%s/%s', $url['para1'], $url['para2']);
echo '<img src="' . $imageUrl . '">'."\n";
}
}
The output is valid html and should visualize the image when used inside an html page:
<img src="https://www.example.com/jferf0923i092eijodsojs">
<img src="https://www.example.com/asjdoisadj829332oijd">
<img src="https://www.example.com/assasdijoj21389445">

Related

PHP - How to group file owner from an array? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have this array:
$files = [
'text.php' => 'Philip Adams',
'help.php' => 'Bobby Barnett',
'video.php' => 'Philip Adams',
'events.php' => 'Bruce Aguilar',
'mysql.php' => 'Bobby Barnett',
'sunday.php' => 'Victoria Rose',
'facebook.php' => 'Bobby Barnett',
'blog.php' => 'Philip Adams',
'view.php' => 'Victoria Rose',
];
Now, I want to make the array like this:
$files = [
'Philip Adams' => [
'text.php',
'video.php',
'blog.php',
],
'Bobby Barnett' => [
'help.php',
'mysql.php',
'facebook.php',
],
'Bruce Aguilar' => [
'events.php',
],
'Victoria Rose' => [
'sunday.php',
'view.php',
],
];
How can I do this?
You can loop the existing array by key/value and push to a new array, something like:
$output = []; // Declare an empty array to hold the output
// Loop the $files array by $file (eg: text.php) and $owner (eg: Philip Adams)
foreach($files as $file => $owner){
$output[$owner][] = $file; // Add the $file to the $owner key in the new array
}
print_r($output); // Output the array
Working example

PHP index array to associative first element equals second and so on [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have an array like this :
$actions = array(
"controller",
"index",
"method",
"default",
);
I want to get the first key equals the second key and so on like this
$actions = array(
"controller" => "index",
"method" => "default"
);
How can i do this thanks !!
Here is an example with for loop:-
<?php
$actions = array(
"controller",
"index",
"method",
"default",
);
for($i = 0; $i < count($actions); $i++)
{
$arr[$actions[$i]] = $actions[$i += 1];
}
echo "<pre>";
print_r($arr);

Confusion in conversion of array to json in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an array $arr_name which prints out
{"name" => "tom", "age" => 10}, {"name" => "jack", "age" => 11}
how do i get it to print the desired output using php ?
Desired Output in JSON is as follows
{
"Students" : [ {"name" => "tom", "age" => 10}, {"name" => "jack", "age" => 11}
]
}
Sorry but i find this very very confusing and have spent the last 2 hrs trying to get "Students" key asssigned to have a value with the contents of $arr_name
PHP already has a built in function to convert an array into JSON:
json_encode
Here simple example given below like:
Put your array place of $put_your_array in loop:
$output=array();
foreach ($put_your_array as $key => $value) {
$output['Students'][]=array(
'name'=>$value['name'],
'age'=>$value['age']
);
}
echo json_encode($output);
And get output would you seem like json format...
the easiest way to do that, loop through the array then assign it to new array
Ex:
$new_array=array();
foreach(your array as $key => $val)
{
$new_array['Students'][] = $val;
}
return json_encode($new_array);

Create Multi Array Json File in PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In My Web Application I am Using Json. I Need to create following Format of Json File in PHP.
{
"title": "A cool blog post",
"clicks": 4000,
"children": null,
"published": true,
"comments": [
{
"author": "Mister X",
"message": "A really cool posting"
},
{
"author": "Misrer Y",
"message": "It's me again!"
}
]
}
Here is the solution:
Open Google
Type PHP JSON
hit Enter
Click the 1st result
Replace the values from PHP examples with json_encode with your own values
json_encode will encode a PHP array as a JSON array.
As the exmaple on that link shows:
<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
// {"a":1,"b":2,"c":3,"d":4,"e":5}

How to call an array by button [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have an array and I want to call the array by button, Also I wanted it keep calling the array every time when I click on button. Please correct the array if it has any issue.
my array is :
array (
"name" => __('name1','vbegy'),
"id" => $this->shortname."_menu_1",
"desc" => __('name2)','vbegy'),
"type" => "text",
"std" => __('name3','vbegy'),
),
array (
"name" => __('name4','vbegy'),
"id" => $this->shortname."_menu_1_url",
"desc" => __('name5)','vbegy'),
"type" => "text",
),
I think first thing you should do is to learn how to use HTML forms/buttons and use PHP to process them. Below is a simple form example.
In your HTML file, add
<form method="post" action="your-php-file.php">
<input type="text" name="text-name" value="">
<input type="submit" name="button-name" value="Submit">
</form>
In your PHP file (your-php-file.php), add
$array1 = array(
"name" => array('name1' => 'vbegy'),
"id" => $this->shortname."_menu_1",
"desc" => array('name2' => 'vbegy'),
"type" => "text",
"std" => array('name3','vbegy')
);
$array2 = array (
"name" => array('name4' => 'vbegy'),
"id" => $this->shortname."_menu_1_url",
"desc" => array('name5' => 'vbegy'),
"type" => "text"
);
if (isset($_POST['button-name'])) {
//use php to process your array data as you want
echo $array1['name']['name1']; //print vbegy
echo $array1['type']; //print text
echo $array2['desc']['name5']; //print vbegy
$std = $array1['std']['name3'];
echo $std; //print vbegy
echo "You clicked submit button!";
}
For detailed explanation, please use following links.
http://www.w3schools.com/php/php_forms.asp
http://www.w3schools.com/php/php_form_complete.asp
Hope this will help.

Categories