Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
How can I store a variable in an external file?
Heres the code:
index.php:
<?php
$info=file('sites/test.php')
$titel=trim($info[1]);
echo $title;
?>
sites/test.php:
line1
line2
line3
What I would like index.php to output:
line1
I cant use include_once, because I only want the first line from sites/test.php
Spoonfeeding, I know:
<?php
$info=file('sites/test.php');
$title=trim($info[0]);
echo $title;
?>
Try this:
<?php
$d=explode("\n", file_get_contents('sites/test.php'));
echo $d[0];
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
i just need on small info i want just add '#' to one variable and and put add thing into one variable. i am adding small php code to here please suggest me.
<?php
$email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_emial.;
echo $tag_name;
?>
but i am getting only # as output;
but my out should be "#mahesh1" if any have idea about this code please help me. thank you advanced.
there is so much spelling mistakes in the variables... try below given code
<?php $email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_email;
echo $tag_name;
?>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am trying to display an image using a variable "$images" that contains the URL parsed form an API.
This is my code:
echo "<td>""<img src='",$image,"'>""</td>\n";
I assume there is a typo I cannot detect because I get a blank screen when running this.
echo "<td>"."<img src='".$image."'>"."</td>";
Or
echo "<td><img src='".$image."'></td>";
You were missing the dots/commas after/before the td tags
use . not ,
<img src='".$image."'>
PHP requires that you chain your strings together using a .
E.g.
echo 'Test' . ' ' . 'Hello'; // Test Hello
Or simply :
echo "<td><img src='$image'></td>";
Check documentation.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Okay this really strange or I am missing something. When I run this very simmple PHP script on cmd I get the expected output which is 0. but when I uncomment the last two lines of code. . .nothing is displayed.
<?php
$test1 = 0;
echo $test1;
$test2 = 0;
#$test1_weight = 0:
#$test2_weight = 0;
?>
Is there some rule against declaring variables after an echo statement?
$test1_weight = 0:
--> change ":" to ";"
No there is no rule against declaring variables after an echo statement
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a PHP file.
<?
$user = "hi";
echo $user;
?>
And nothing happens, its just blank. It should say "hi". I am using xampp to run the PHP and it is saved in the right place but nothing happens.
you should use <?php instead of <?
try this:
<?php
$user = "hi";
echo $user;
?>
or Set
short_open_tag=On
in php.ini
And restart your Apache server.
You need to activate php short open tag from php settongs or replace : <? with <?php
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have about 300 lines of text that need to be echoed randomly.
Here's my current code:
<?php
$lines = array(
'Line 1',
'Line 2',
'Line 3'
);
$powered = echo $lines[rand(0, count($lines)-1)];
echo $powered;
?>
I know that the issue is probably with line 9 because I'm not sure how to assign the echoing to a variable. I need to be able to include this file in several others and echo $powered to get a random line.
Any help would be really appreciated.
$lines = array("one", "two", "three","four");
for($i =0; i < count($lines)-1;i++){
$line = $lines[rand(0, count($lines)-1)];
$lines = array_diff($lines, array($line));//Use this to remove the index of array
}
i wrote this in the stack overflow chat so there might be a problem or two. though, all looks well to me.
Was this what you were looking for?