Okay i've got this working with the $_POST["HTMLSourceCode"]
like following:
Text area:
<!-- Text area -->
<div class="form-group sourceCode resourceBox">
<textarea class="form-control" name="HTMLSourceCode" id="HTMLSourceCode" rows="3" placeholder="Source code"></textarea>
</div>
Source code:
// Source code which is posted within textarea
<div id="element_36866219" class="element element-slideshow" >
<div class="sj_element_slideshow "><h2 class="custom_title"></h2><div class="sj-block-center" style="position: relative; max-width:100%; height:0; padding-bottom:60%;"><div id="sj_element_slideshow_36866219" class="cycle" style="position: absolute; width: 100%; height: 100%;"><div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305401" data-original="https://img.cdn.schooljotter2.com/sampled/10305401/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305446" data-original="https://img.cdn.schooljotter2.com/sampled/10305446/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305449" data-original="https://img.cdn.schooljotter2.com/sampled/10305449/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305452" data-original="https://img.cdn.schooljotter2.com/sampled/10305452/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305455" data-original="https://img.cdn.schooljotter2.com/sampled/10305455/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305458" data-original="https://img.cdn.schooljotter2.com/sampled/10305458/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305461" data-original="https://img.cdn.schooljotter2.com/sampled/10305461/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305464" data-original="https://img.cdn.schooljotter2.com/sampled/10305464/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305466" data-original="https://img.cdn.schooljotter2.com/sampled/10305466/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305469" data-original="https://img.cdn.schooljotter2.com/sampled/10305469/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305472" data-original="https://img.cdn.schooljotter2.com/sampled/10305472/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305478" data-original="https://img.cdn.schooljotter2.com/sampled/10305478/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305482" data-original="https://img.cdn.schooljotter2.com/sampled/10305482/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305485" data-original="https://img.cdn.schooljotter2.com/sampled/10305485/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305488" data-original="https://img.cdn.schooljotter2.com/sampled/10305488/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305493" data-original="https://img.cdn.schooljotter2.com/sampled/10305493/1200/720" /></div>
<div style='position: absolute; top: 0; left: 0;'><img class="lazy" style="width: auto; height: auto; max-width: 100%; max-height: 100%;" data-outline="" data-host="https://img.cdn.schooljotter2.com/sampled/" data-width="100" data-height="60" data-id="10305495" data-original="https://img.cdn.schooljotter2.com/sampled/10305495/1200/720" /></div>
</div></div></div>
<div id="element_36866220" class="element element-text" >
preg_match_all()
// This is from textarea
preg_match_all('/<img[^>]+>/i', $_POST["HTMLSourceCode"], $result);
However the problem i'm having is when the $_POST["HTMLSourceCode"]
is turned into a string
then the preg_match_all()
turns back an empty $result
array
Not working example:
<div class="form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 selectorTags left">
<input type="text" class="form-control" name="startingTag" id="startingTag" placeholder="Starting Tag">
</div>
<div class="form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 selectorTags right">
<input type="text" class="form-control" name="endingTag" id="endingTag" placeholder="Ending Tag">
</div>
<div class="form-group sourceCode resourceBox">
<textarea class="form-control" name="HTMLSourceCode" id="HTMLSourceCode" rows="3" placeholder="Source code"></textarea>
</div>
starting tag:
<div id="element_36866219" class="element element-slideshow" >
ending tag:
<div id="element_36866220" class="element element-text" >
$HTMLSourceCode = "";
if(isset($_POST["startingTag"]) && !empty($_POST["startingTag"]) && isset($_POST["endingTag"]) && !empty($_POST["endingTag"])){
$tagArrayTemp = array();
$tagArrayTemp = array_values(array_filter(explode(htmlentities($_POST["startingTag"]), htmlentities($_POST["HTMLSourceCode"]))));
$tagArray = array_values(array_filter(explode(htmlentities($_POST["endingTag"]), $tagArrayTemp[0])));
if($tagArray[0]){
$HTMLSourceCode = $tagArray[0];
} else {
$HTMLSourceCode = $_POST["HTMLSourceCode"];
}
} else {
$HTMLSourceCode = $_POST["HTMLSourceCode"];
}
if(!empty($_POST["HTMLSourceCode"])){
preg_match_all('/<img[^>]+>/i', $HTMLSourceCode, $result);
}
print_r($result);
exit;
Result:
Array ( [0] => Array ( ) )
Expected result: (Based on working example)
Array ( [0] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => [20] => [21] => [22] => [23] => [24] => [25] => [26] => [27] => [28] => ) )