How can I make a show more button in HTML? I'm importing some text trough a variable in how do I make it so that like 20 characters are being showed and the rest will be showed once the button is pressed. This is what I have now:
$array = explode("<br>", $array_build->content);
foreach( $array as $key => $value){
if (
strpos(strtolower($value),'value1') !== FALSE ||
strpos(strtolower($value),'value2') !== FALSE ||
strpos(strtolower($value),'value3') !== FALSE ||
strpos(strtolower($value),'value4') !== FALSE
) {
unset($array[$key]);
}
};
$newcontent = "<pre>".implode("\n",$array)."</pre>";
?>
<div style="margin-top: 50px;"></div>
<style>
.button {
border-radius: 4px;
background-color: #002B56;
color: white;
padding: 14px 40px;
}
</style>
<div style="text-align: center;">
<script type="text/javascript">
function toggle(obj) {
var obj=document.getElementById(obj);
if (obj.style.display == "block") obj.style.display = "none";
else obj.style.display = "block";
}
</script>
<a class="button" href="javascript: void(0);" onClick="toggle('q1')">
Show More
</a>
<div style="margin-top: 50px;"></div>
<div id="q1" style="display:none;">
<div class="col" style="width: 100%;"><?= $newcontent ?></div>
</div>
</div>
Output I want:
Lorem ipsum dolor sit amet.
SHOW MORE
consectetur adipiscing elit. Integer tellus erat, tempor quis dolor a, gravida eleifend leo. Orci varius.
` instead. Browsers will render that as an expand/collapse widget.