How can I separate CSS elements and values using regex? - regex

I have CSS file and want to separate elements and values in form fields to make it editable using regular expressions.
This is my CSS:
<cfsavecontent variable="css">
.input-block-level {
display: block;
width: 100%;
min-height: 30px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
##map_canvas img,
.google-maps img {
/*edit*/max-width: none;
}
#sup {
position: relative;
font-size: 75%;
line-height: 0;
vertical-align: baseline;
}
</cfsavecontent>
I have tried the expression below to extract the elements between the opening and closing braces. It works fine but I am wondering how to get elements and values delimited by lines.
<cfset reg1 = REMatch("{(?i)(.+?)}",css) />
<cfdump var="#reg1#" label="braces">
How can I write a regex pattern to separate the elements and values? Thanks in advance.

This works for me to split up the items and values, not sure it's exactly what you're needing though:
<cfset reg1 = REMatch("{(?i)(.+?)}",css) />
<cfloop index="item" array="#reg1#">
<cfset lines = listToArray(item, Chr(10))>
<cfloop index="line" array="#lines#">
<cfset arrLine = listToArray(line, ":")>
<cfif arrayLen(arrLine) EQ 2>
<cfset item = trim(arrLine[1])>
<cfset value = trim(arrLine[2])>
<cfoutput>
item: #item#<br>
value: #value#<br>
<br>
</cfoutput>
</cfif>
</cfloop>
</cfloop>

Related

Preg Replace an entire div

I am really trying to use preg_replace an entire div and it's contents.
I've looked around quite a bit and found some similar examples.
Being a total newbie, i would greatly appreciate your advise.
Please be aware that there are nested divs within this div, but with different classes or id.
This is what i have tried, but with no success.
[preg_replace("/<div class="ads-wrapper">/(.+?)<\/div>s","",{title_article[1]})]
I should also point out that this is to be used with WP All Import.
EDIT //
Sample HTML
<body>
<div class="ads-wrapper">
<div style="margin-left: auto; margin-right: auto; text-align: center; " id="filexxxxxxx" data-cfptl="1" data-cfpa="69067" data-cfpw="69067"><script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxx" crossorigin="anonymous" data-checked-head="true"></script><ins class="adsbygoogle" style="display: block; height: 280px;" data-ad-client="ca-pub-xxxxxxxxxxxx" data-ad-slot="xxxxxxx" data-ad-format="auto" data-full-width-responsive="true" data-adsbygoogle-status="done" data-ad-status="filled"><p></p>
<div id="aswift_2_host" style="border: medium none; height: 280px; width: 752px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block; overflow: visible;" tabindex="0" title="Advertisement" aria-label="Advertisement"><iframe id="aswift_2" name="aswift_2" style="left:0;position:absolute;top:0;border:0;width:752px;height:280px;" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-xxxxxxxxxx&output=html&h=280&slotname=7139257958&adk=4289402179&adf=1131929206&pi=t.ma~as.7139257958&w=752&fwrn=4&fwrnh=100&lmt=1671441700&rafmt=1&format=752x280&url=https%3A%2F%2Ffilecr.com%2Fwindows%2Fadobe-indesign-2022-0002%2F%3Fid%3D937678064&fwr=0&fwrattr=true&rpe=1&resp_fmts=3&wgl=1&dt=1671441699033&bpp=5&bdt=1086&idt=828&shv=r20221207&mjsv=m202212050101&ptt=9&saldr=aa&abxe=1&cookie=ID%3D65a8c8bc760cb659-229ca8d322d90053%3AT%3D1671441677%3ART%3D1671441677%3AS%3DALNI_MYstdfFdvqDMbBT89kWi_GbmnW5Fw&gpic=UID%3D000008d9fc9b2725%3AT%3D1671441677%3ART%3D1671441677%3AS%3DALNI_MaA7dhdMS9LxBPtWwmg_Ho-5cQXWg&prev_fmts=0x0%2C1158x280&nras=1&correlator=536657398109&frm=20&pv=1&ga_vid=223145590.1671441677&ga_sid=1671441700&ga_hid=667781215&ga_fc=1&u_tz=0&u_his=1&u_h=1080&u_w=1920&u_ah=1080&u_aw=1920&u_cd=24&u_sd=1&adx=240&ady=1017&biw=1587&bih=1080&scr_x=0&scr_y=0&eid=44759875%2C44759926%2C44759837%2C44777508%2C31071219%2C31071259%2C44780792&oid=2&pvsid=4107435780668556&tmod=302213105&nvt=1&ref=https%3A%2F%2Ffilecr.com%2F%3Fs%3DAdobe&eae=0&fc=1920&brdim=%2C%2C0%2C0%2C1920%2C0%2C1920%2C1080%2C1600%2C1080&vis=1&rsz=%7C%7CeE%7C&abl=CS&pfx=0&fu=128&bc=29&ifi=3&uci=a!3&xpc=qnZUlMsEJP&p=https%3A//filecr.com&dtd=1078" data-google-container-id="a!3" data-google-query-id="CMm1s8athfwCFUrdhwodNQoNmA" data-load-complete="true" width="752" height="280" frameborder="0"></iframe></div>
<p><br>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</p></ins></div>
<p><script type="text/javascript">;new advadsCfpAd( 69067 );</script> </p></div>
</body>
Here is the code tested on https://www.jdoodle.com/php-online-editor/
I am using a small HTML minifier function vh_html_minifier that will remove the line breaks since I am unsure if the preg replace can be done with keeping the line breaks or not.
/**
* HTML Minifier function
*
* #param string $code HTML string.
* #return string
*/
function vh_html_minifier( $code ) {
$search = array(
// Remove whitespaces after tags.
'/\>[^\S ]+/s',
// Remove whitespaces before tags.
'/[^\S ]+\</s',
// Remove multiple whitespace sequences.
'/(\s)+/s',
// Removes comments.
'/<!--(.|\s)*?-->/',
);
$replace = array( '>', '<', '\\1' );
$code = preg_replace( $search, $replace, $code );
return $code;
}
$html = '<body>
<div class="ads-wrapper">
<div style="margin-left: auto; margin-right: auto; text-align: center; " id="filexxxxxxx" data-cfptl="1" data-cfpa="69067" data-cfpw="69067"><script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxx" crossorigin="anonymous" data-checked-head="true"></script><ins class="adsbygoogle" style="display: block; height: 280px;" data-ad-client="ca-pub-xxxxxxxxxxxx" data-ad-slot="xxxxxxx" data-ad-format="auto" data-full-width-responsive="true" data-adsbygoogle-status="done" data-ad-status="filled"><p></p>
<div id="aswift_2_host" style="border: medium none; height: 280px; width: 752px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block; overflow: visible;" tabindex="0" title="Advertisement" aria-label="Advertisement"><iframe id="aswift_2" name="aswift_2" style="left:0;position:absolute;top:0;border:0;width:752px;height:280px;" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-xxxxxxxxxx&output=html&h=280&slotname=7139257958&adk=4289402179&adf=1131929206&pi=t.ma~as.7139257958&w=752&fwrn=4&fwrnh=100&lmt=1671441700&rafmt=1&format=752x280&url=https%3A%2F%2Ffilecr.com%2Fwindows%2Fadobe-indesign-2022-0002%2F%3Fid%3D937678064&fwr=0&fwrattr=true&rpe=1&resp_fmts=3&wgl=1&dt=1671441699033&bpp=5&bdt=1086&idt=828&shv=r20221207&mjsv=m202212050101&ptt=9&saldr=aa&abxe=1&cookie=ID%3D65a8c8bc760cb659-229ca8d322d90053%3AT%3D1671441677%3ART%3D1671441677%3AS%3DALNI_MYstdfFdvqDMbBT89kWi_GbmnW5Fw&gpic=UID%3D000008d9fc9b2725%3AT%3D1671441677%3ART%3D1671441677%3AS%3DALNI_MaA7dhdMS9LxBPtWwmg_Ho-5cQXWg&prev_fmts=0x0%2C1158x280&nras=1&correlator=536657398109&frm=20&pv=1&ga_vid=223145590.1671441677&ga_sid=1671441700&ga_hid=667781215&ga_fc=1&u_tz=0&u_his=1&u_h=1080&u_w=1920&u_ah=1080&u_aw=1920&u_cd=24&u_sd=1&adx=240&ady=1017&biw=1587&bih=1080&scr_x=0&scr_y=0&eid=44759875%2C44759926%2C44759837%2C44777508%2C31071219%2C31071259%2C44780792&oid=2&pvsid=4107435780668556&tmod=302213105&nvt=1&ref=https%3A%2F%2Ffilecr.com%2F%3Fs%3DAdobe&eae=0&fc=1920&brdim=%2C%2C0%2C0%2C1920%2C0%2C1920%2C1080%2C1600%2C1080&vis=1&rsz=%7C%7CeE%7C&abl=CS&pfx=0&fu=128&bc=29&ifi=3&uci=a!3&xpc=qnZUlMsEJP&p=https%3A//filecr.com&dtd=1078" data-google-container-id="a!3" data-google-query-id="CMm1s8athfwCFUrdhwodNQoNmA" data-load-complete="true" width="752" height="280" frameborder="0"></iframe></div>
<p><br>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</p></ins></div>
<p><script type="text/javascript">;new advadsCfpAd( 69067 );</script> </p></div>
</body>';
$result = preg_replace( '#<div class="ads-wrapper">(.*?)</div>#', ' ', vh_html_minifier( $html ) );
echo '<pre>' . $result . '</pre>';

Display rows in 2 columns

I would like to display my row on 2 columns,
but for a reason it is only displaying the first entry on 2 rows.('name' on 1 row /'grouped_id' other row.
Not all entries of my database.
I missed something know with $row=.
Can you help me ? I would like display 'name' 'grouped_id' on each row:
my code
<title>TITLE</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght#700;800;900&display=swap" rel="stylesheet">
<style>
body {background-color: #000000;}
table {
background-color: #000000;
border-collapse: collapse;
width: 100%;
}
table, .table {
color: #fff;
font-family: "Montserrat", sans-serif;
font-size: 18px;
font-weight:800;
font-weight:Extra-bold;
}
tr:nth-child(even) {
background-color: #60451e;
}
</style>
<div class="container">
<div class="row">
<?php
include_once("inc/db_connect.php");
$sqlQuery = "SELECT name, GROUP_CONCAT(id ORDER BY id SEPARATOR ' | ') as grouped_id FROM developers GROUP BY name";
$resultSet = mysqli_query($conn, $sqlQuery) or die("database error:". mysqli_error($conn));
?>
<table id="editableTable" class="table table-bordered">
<tbody>
<?php
// represents your database rows
$rows = mysqli_fetch_array($resultSet);
$length = count($rows);
$halfIndex = ceil($length / 2);
$currentRow = 0;
while ($currentRow < $halfIndex) {
$leftIndex = $currentRow;
$rightIndex = $halfIndex + $currentRow;
$leftColumn = $rows[$leftIndex] ?? '--';
$rightColumn = $rows[$rightIndex] ?? '--';
echo "<tr>";
echo "<td>{$leftColumn}</td>";
echo "<td>{$rightColumn}</td>";
echo "</tr>";
$currentRow++;
}
?>
</tbody>
</table>
</div>
</div>
Have a look at the official documentation https://www.php.net/manual/en/mysqli-result.fetch-array.php
or here for a brief summary https://www.w3schools.com/php/func_mysqli_fetch_array.asp
The result of mysqli_fetch_array is a an array of array: a list of samples where each sample is a list of fields from the query table.

overlay text over a image in foundation

Hi I have the following foundation codepen:
https://codepen.io/ianims/pen/PmoqBZ
code:
$(document).ready(function () {
$(document).foundation();
});
body {
background-color: #a3d5d3;
}
#wrap {
position:relative; /* make this relative to have the inner div absolute without breaking out */
/* width: 200px; /* fix the width or else it'll be the entire page's width */
background: silver;
border: 1px solid grey
}
#text {
color:#ffffff;
margin-left: 70%;
position: absolute;
width:250px;
height:60%;
top: 0;
bottom: 0;
background: black;
opacity:0.5;
padding :20px;
}
<div class="row fullWidth">
<div class="large-12 columns">
<div id="wrap">
<div id="text">
<br /><br /><br /><br />
<h3>MCA Coding and MLC Compliance</h3>
<p>
This is some text which I need to show on the right hand side. This is some text which I need to show on the right hand side. This is some text which I need to show on the right hand side. This is some text which I need to show on the right hand side.
</p>
</div>
<img src="https://www.burgessyachts.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/0/00006250_13.jpg" />
</div>
</div>
</div>
On a large screen it works ok -- I want the text overplayed on the image over to the right - but if you shrink the screen down the text starts to disappear off to the right -- anyone any ideas how to keep it consistent on all screens???
thanks
It's better to position using the left: position as opposed to margin. You might also want to delete the height property so it accomodates more content.
#text {
padding-top: 2em; /*replaces the <br>s in your html*/
color: #ffffff;
position: absolute;
width: 250px;
/*height: 60%;*/
top: 0;
right:7.5%; /* instead of margin*/
background: black;
opacity: 0.5;
padding: 20px;
}
I made a codepen demo:
https://codepen.io/kemie/pen/pPoqOv

PHP - preg_replace and str_replace only replace only once inside foreach

I have a foreach that uses a Glob function in order to get some .htm files and finally put that content in one echo.
I Tried to replace one specific phrase located in all this .htm files with some data that I extract from the each .htm filename.
So,
$juzgado_radicado generates a number like ---> 004
$year_radicado generates a number like ---> 2015
$radicado_radicado generates a number like ---> 00911
That numbers are changing depending of foreach iteration getting a new file name.
But at the end I use preg_replace or str_replace in order to change a phrase inside the each .htm document but instead replacing the numbers in each iteration I only get the same result in all replaces. So I get something like "00911" in all .htm files and it have to be something like "00911" and "00577" por example.
I don't know why preg_replace and str_replace have this behaviour inside the foreach loop.
$directory2 = "/Applications/XAMPP/xamppfiles/htdocs/tecnojuridica/finalizado/";
$array_filename = glob($directory2 . "*.htm");
$string = '';
foreach($array_filename as $filename)
{
$xml_file = file_get_contents($filename, FILE_TEXT);
preg_match('/[0-9]{23}/', $filename, $match);
$radicado = $match[0];
// 002
$juzgado_radicado = substr($radicado, -14, 3);
// 2015
$year_radicado = substr($radicado, -11, 4);
// 00958
$radicado_radicado = substr($filename, -7, 5);
// Dom Object
$dom = new DOMDocument('1.0', 'utf-8');
$dom->xmlStandalone = true;
$dom->loadHTML($xml_file);
$content_node = $dom->getElementById("divrandom");
$mega = $dom->saveXML($content_node);
$string2 = preg_replace('/Datos del Proceso/', ' <font size="30"> <span style="background-color: #73A6FF; color: #fff; display: inline-block; padding: 3px 10px; font-weight: bold; border-radius: 5px;">' . $juzgado_radicado . '</span> <span style="background-color: #73A6FF; color: #fff; display: inline-block; padding: 3px 10px; font-weight: bold; border-radius: 5px;">' . $year_radicado . '</span> <span style="background-color: #73A6FF; color: #fff; display: inline-block; padding: 3px 10px; font-weight: bold; border-radius: 5px;">' . $radicado_radicado . ' </span> </font>', $mega);
$string.= $mega . ',';
}
echo utf8_decode($string2);
Thanks in advance.
I've found the Answer: You have to replace at star of the foreach loop not with Php Dom Document Objects.
If you tried to make replacement into Dom Objects it's possible that fails because str_replace of preg_replace can't make all iterations with different replace data.

cfgrid and cfajaximport mouseover

I have the following:
<cfajaximport/>
<html>
<head>
<script>
myf = function(data,cellmd,record,row,col,store) {
if(data == "Product 4")
return "<b>" + data + "</b>";
else return data;
}
testgrid = function() {
mygrid = ColdFusion.Grid.getGridObject('data');
ds = mygrid.getDataSource();
cm = mygrid.getColumnModel();
cm.setRenderer(0, Ext.util.Format.usMoney);
cm.setRenderer(1,myf);
}
</script>
</head>
<body>
<cfset data = queryNew("price,product")>
<cfloop from=1 to=10 index="x">
<cfset total = randRange(20,100) & "." & randRange(1,99)>
<cfset product = "Product #X#">
<cfset queryAddRow(data)>
<cfset querySetCell(data, "price", total+0, x)>
<cfset querySetCell(data, "product", product, x)>
</cfloop>
<cfform name="test">
<cfgrid autowidth="true" name="data" format="html" query="data" width="600">
<cfgridcolumn name="price" header="Price">
<cfgridcolumn name="product" header="Product">
</cfgrid>
</cfform>
<cfset ajaxOnLoad("testgrid")>
</body>
</html>
Picked up from Raymond Camden's blog. I need to somehow add a mouseover event to product column to display product details. (like cost).
Any help on how to implement this event?
I ended up creating html inside the query cell.
<cfset product =
'' & Product#x# & ''>
Otherwise, you will need to play with extJs.