Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 向字符串中的每个图像添加超链接和类_Html_Image_Tags_Lightbox_Summernote - Fatal编程技术网

Html 向字符串中的每个图像添加超链接和类

Html 向字符串中的每个图像添加超链接和类,html,image,tags,lightbox,summernote,Html,Image,Tags,Lightbox,Summernote,我使用Summernote发布博客,但使用代码片段将图像直接上传到服务器,而不是在文本中,代码如下所示: <script>$(document).ready(function() { $("#summernote").summernote({ callbacks: { onImageUpload : function(files, editor, welEditable) { for(var i = files.lengt

我使用Summernote发布博客,但使用代码片段将图像直接上传到服务器,而不是在文本中,代码如下所示:

<script>$(document).ready(function() {
$("#summernote").summernote({
         callbacks: {
        onImageUpload : function(files, editor, welEditable) {

             for(var i = files.length - 1; i >= 0; i--) {
                     sendFile(files[i], this);
            }
        }
    }
    });
});
function sendFile(file, el) {
var form_data = new FormData();
form_data.append('file', file);
$.ajax({
    data: form_data,
    type: "POST",
    url: 'editor-upload.php',
    cache: false,
    contentType: false,
    processData: false,
    success: function(url) {
        $(el).summernote('editor.insertImage', url);
    }
});
}
</script>

<?php
if(empty($_FILES['file']))
{
    exit();
}
$errorImgFile = "./img/img_upload_error.jpg";
$temp = explode(".", $_FILES["file"]["name"]);
$newfilename = round(microtime(true)) . '.' . end($temp);
$destinationFilePath = './img-uploads/'.$newfilename ;
if(!move_uploaded_file($_FILES['file']['tmp_name'], $destinationFilePath)){
    echo $errorImgFile;
}
else{
    echo $destinationFilePath;
}

?>
$(文档).ready(函数(){
$(“#summernote”)。summernote({
回调:{
onImageUpload:功能(文件、编辑器、可编辑){
对于(var i=files.length-1;i>=0;i--){
sendFile(文件[i],本);
}
}
}
});
});
函数sendFile(文件,el){
var form_data=new FormData();
表单_data.append('file',file);
$.ajax({
数据:表格数据,
类型:“POST”,
url:'editor upload.php',
cache:false,
contentType:false,
processData:false,
成功:函数(url){
$(el).summernote('editor.insertImage',url);
}
});
}
我现在正在尝试将Lightbox包含到嵌入的图像中,但无法找到一种方法来单独更改img标签来实现这一点?例如,

$string = '<img src="firstimg.jpg"> a little bit of text <img src="secondimg.jpg">';
$string='一点文字';
我需要把它转换成类似于

<a class="example-image-link" href="firstimg.jpg" data-lightbox="example-set"><img class="example-image" src="firstimg.jpg"></a> a little bit of text <a class="example-image-link" href="secondimg.jpg" data-lightbox="example-set"><img class="example-image" src="secondimg.jpg"></a>
一点文字
我到处找了,但找不到任何帮助?任何帮助都将不胜感激

let$string=`一点文本`
let parser=new DOMParser()
让_document=parser.parseFromString($string,“text/html”)
让ele=\u document.getElementsByTagName(“IMG”)
for(设i=0;iconsole.log(newStr)
虽然这似乎有效,但我不熟悉这类代码,似乎无法使其在我的站点中运行?你能把它添加到像w3schools这样的地方,这样我就可以看到它是如何添加的了吗?您可以签出此代码段