php变量包含和html代码包含一个php变量

时间:2017-05-25 11:00:32

标签: php html

有可能吗?

这是php代码:

echo '<img src="data:image/jpeg;base64,'.base64_encode($data['photo1']).'" height="100" width="100"/>';

我想将它包含在一个html代码中,该代码也存储在php变量中:

$var = "
 <div>
 the first code
 </div>";
echo $var;

怎么做?

5 个答案:

答案 0 :(得分:1)

将第一个字符串存储在变量中,而不是回显它。

$img = '<img src="data:image/jpeg;base64,'.base64_encode($data['photo1']).'" height="100" width="100"/>';

然后您可以将其替换为另一个字符串:

$var = "
 <div>
 $img
 </div>";
echo $var;

答案 1 :(得分:0)

你可以这样做:

<?php 
  $var = '<div><img src="data:image/jpeg;base64,'.base64_encode($data['photo1']).'" height="100" width="100"/></div>';
  echo $var; 
?>

答案 2 :(得分:0)

这将对您有所帮助: -

// Initialize Storage
        //storage
        mStorage = FirebaseStorage.getInstance("gs://<bucket_name>");
        mStorageRef = mStorage.getReference();

    final StorageReference downloadRef;
            downloadRef = mStorageRef.getRoot().child(downloadPath);

            try {
                File output = new File(Environment.getExternalStorageDirectory() + File.separator + Config.MY_VIDEOS_PATH);
                if (!output.exists()) {
                    output.mkdir();
                }
                localFile = new File(output, downloadId);
            } catch (Exception e) {
                e.printStackTrace();
            }


            // Download and get total bytes
            downloadRef.getFile(localFile)
                    .addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
                        @Override
                        public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
                            showProgressNotification(1,title, "",
                                    taskSnapshot.getBytesTransferred(),
                                    taskSnapshot.getTotalByteCount());
                        }
                    })
                    .addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                            Log.d(TAG, "download:SUCCESS");
                            // Send success broadcast with number of bytes downloaded
                            broadcastDownloadFinished(downloadPath, taskSnapshot.getTotalByteCount());
                            showDownloadFinishedNotification(downloadPath, (int) taskSnapshot.getTotalByteCount());

                            // Mark task completed
                            taskCompleted();
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception exception) {
                            Log.w(TAG, "download:FAILURE", exception);
                            Log.w(TAG, "download:FAILURE", exception.getCause());

                            // Send failure broadcast
                            broadcastDownloadFinished(downloadPath, -1);
                            showDownloadFinishedNotification(downloadPath, -1);

                            // Mark task completed
                            taskCompleted();
                        }
                    });

答案 3 :(得分:0)

尝试像这样的东西

$var = "
 <div>
 <img src='data:image/jpeg;base64',".base64_encode($data['photo1'])." height='100' width='100'/>
 </div>";

答案 4 :(得分:0)

虽然这是一种不好的方法,但为什么不这样做,

$var = "<div>";
$var .= '<img src="data:image/jpeg;base64,'.base64_encode($data['photo1']).'" height="100" width="100"/>';
$var.= "</div>";

然后

echo $var;