I'm trying to replace some strings using regex in HTML, but there are Swedish characters that make my life difficult.
It starts off looking like this (I'm using dummy text instead of the real Swedish):
<td class="swedish">abc defgå hijk lmnopä</td>
<td><?php audioButton("../../audio/lessons/01/some_old_text","some_old_text"); ?></td>
<td><?php audioButton("../../audio/lessons/01/slow/some_old_text_slx","some_old_text_slx","1"); ?></td>
Step 1: I manage to place the string in the first tag inside the audiobutton, so it looks like this:
<td class="swedish">abc defgå hijk lmnopä</td>
<td><?php audioButton("../../audio/lessons/01/abc defgå hijk lmnopä","abc defgå hijk lmnopä"); ?></td>
<td><?php audioButton("../../audio/lessons/01/slow/abc defgå hijk lmnopä_slx","abc defgå hijk lmnopä_slx","1"); ?></td>
You don't have to read this, but I did it with the following:
Find
<td class="swedish">(.*)</td>\n.*<td><\?php audioButton\("(.*)/.*",".*"\); \?></td>\n.*<td><\?php audioButton\("(.*)/.*",".*","1"\); \?></td>
Replace
<td class="swedish">$1</td>
<td><?php audioButton("$2/$1","$1"); ?></td>
<td><?php audioButton("$3/$1_slx","$1_slx","1");?></td>
It's fairly straightforward, even for a noob like myself.
Step 2: Now this is where my problems begin. The Swedish characters ä, ö and å have special codes in HTML (ä - ö and å). I have to replace each instance of that code with ae, oe and aa respectively, and put an underscore between each word. This has to happen inside the audiobutton only.
The final result has to look like this:
<td class="swedish">abc defgå hijk lmnopä</td>
<td><?php audioButton("../../audio/lessons/01/abc_defgaa_hijk_lmnopae","abc_defgaa_hijk_lmnopae"); ?></td>
<td><?php audioButton("../../audio/lessons/01/slow/abc_defgaa_hijk_lmnopae_slx","abc_defgaa_hijk_lmnopae_slx","1"); ?></td>
This is where my regex literacy fails me. It's probably really simple, but I can't see it. I would really appreciate some help. It would be especially great if I can do the whole thing in one step instead of two.
Here's a bash loop that will replace the audioButton occurrences as you wish:
for line in $(egrep "audioButton" swedish.txt | sed -e 's?\ ?::ZZqC::?g') ; do
real_line=$(echo "${line}" | sed -e 's?::ZZqC::?\ ?g') ;
new_line=$(echo "${real_line}" | sed -e 's?ä?ae?g' -e 's?ö?oe?g' -e 's?å?aa?g' -e 's?\([a-z]\) ?\1_?g') ;
sed -i -e "s|${real_line}|${new_line}|g" swedish.txt ;
done
Related
this is my first question on stackoverflow.
I have a mysql table on my website that list earthquake origins, they all have latitudes and longitudes in the same table.
An example:
Date | Time | Latitude | Longitude | Depth | magnitude | Magnitude type
2017/04/03 | 03:08:37.20 | -26.762 | 26.627 | 261.0 | 3.9 | WFEO
How can I add a reverse geolocation field in the same table where an approximate location name will be displayed?
I thought of downloading the Geonames database, and then putting that in a different table, and then querying the second table, but I don't know.
The mysql server is on a remote webserver.
Note: I am looking for a solution that will do each and every row in the table.
Thanks, I am new to mysql, so I don't have much knolledge in the field.
Any help would be appreciated.
What I've done so far.
I have a csv file which the earthquake parameters get recorded in, I've managed to put that in a mysql database to display as an html table. The code follows:
<?php
$db = new mysqli('localhost:3306','user','password','database');
if ($db->connect_errno) {
echo "Failed to connect to MySQL: " . $db->connect_error;
exit();
}
?>
<table align="center" width="800" border="1" style="border-collapse:collapse; border:1px solid #ddd;" cellpadding="5" cellspacing="0">
<thead>
<tr bgcolor="#FFCC00">
<th>Date</th>
<th>Time</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Depth</th>
<th>magnitude</th>
<th>magnitude type</th>
</tr>
</thead>
<tbody>
<?php
if(($handle = fopen("norcsv.txt", "r")) !== FALSE){
$n = 1;
while(($row = fgetcsv($handle)) !== FALSE){
$db->query('INSERT INTO `events`(`date`, `time`, `latitude`, `longitude`, `depth`, `magnitude`, `magtype`) VALUES ("'.$row[1].'","'.$row[2].'","'.$row[3].'","'.$row[4].'","'.$row[5].'","'.$row[6].'")');
if($n>1){
?>
<tr>
<td><?php echo $row[0];?></td>
<td><?php echo $row[1];?></td>
<td><?php echo $row[2];?></td>
<td><?php echo $row[3];?></td>
<td><?php echo $row[4];?></td>
<td><?php echo $row[5];?></td>
<td><?php echo $row[6];?></td>
</tr>
<?php
}
$n++;
}
fclose($handle);
}
?>
</tbody>
</table>
View last seismic event location on a map.
So as you can see, everything works, now I want to add a placename field in the current existing table to use the latitudes and longitudes to compute a geographical placename or maybe distance to placename.
Hope my question is clearer now.
Thanks everyone.
I need to show my associated products custom attribute like size,color under Grouped product. Inside the below table code. I am a beginner in magento project. Please give a solution.
<?php foreach ($_associatedProducts as $_item): ?>
<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
<tr>
<td><!--Color--></td>
<td><!--Size--></td>
I found the below code which solved my problem.
<td><?php echo $this->htmlEscape($_item->getAttributeText('shirtcolor')); ?></td>
<td><?php echo $this->htmlEscape($_item->getAttributeText('shirtsize')); ?></td>
If anybody tried solution for my question Thank You!
How can I will use substr in detail field?
This is my code:
<td><?php echo $newses['details']; ?></td>
If $newses['details'] is type of string just use:
<?php echo substr($newses['details'], 0, 10); ?>
But if you want to do it in CakePHP way, use truncate() method of TextHelper.
you can use this
echo $this->Text->truncate(
$newses['details'],
10
);
I have a database table and I want to print the name. It isn't displayed correct, it's like this:
Abu Noooooora dddd#hotmail.com
���� ������� dddd#hotmail.com
almojaded dddd#islamway.net
WeldLibya dddd#hotmail.com
What can I do to print like:
Abu Noooooora dddd#hotmail.com
يوسف على dddd#hotmail.com
almojaded dddd#islamway.net
WeldLibya dddd#hotmail.com
My php code is:
<?
$dd = mysql_query("SELECT sname,semail FROM senders LIMIT 5");
while($ro = mysql_fetch_array($dd))
{
?>
<tr>
<td style="text-align:right;"><?php echo $ro["sname"]; ?></td>
<td style="text-align:right;"><?php echo $ro["semail"]; ?></td>
</tr>
<?
}
?>
Looks like you are using MySQL. Suggest you read this http://dev.mysql.com/doc/refman/5.6/en/charset.html.
Can you tell if MySQL is set up for unicode (international) character sets. You can use some of the MySQL admin tools to check this. YOu need to know the name of the character set you want to use, and check if it is loaded into your MySQL installation.
At the HTML level, you need to specify that you are using utf8 output by placing something like
in your header area
Help me!!
Seem when i run the scripts, the output seems wrong :(
This is the output...
Here My Output
The 1st and 3rd entry is true, online
But the rest should be OFFLINE but the output shows all ONLINE
I think the problem is from foreach loop but I cannot figure out how to solve the problem
Please help me... :(
<table border="1">
<thead>
<tr>
<th>Entry</th>
<th>Host</th>
<th>Name</th>
<th>Location</th>
<th>Description</th>
<th>Availability</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM host_entry";
$no = 1;
//foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row)
$dbhi = $dbh->query($sql);
foreach ($dbhi->fetchAll(PDO::FETCH_BOTH) as $data) {
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $data['host_server']; ?></td>
<td><?php echo $data['host_name']; ?></td>
<td><?php echo $data['host_location']; ?></td>
<td><?php echo $data['host_desc']; ?></td>
<td>
<?php
$ip = $data["host_server"];
// Run the ping to the IP
exec ("ping -n 1 -w 1 $ip", $ping_output);
if(preg_match("/Reply/i", $ping_output[2])!==0) {
echo "<font color='green'><strong>Online!</strong></font>";
}
else if(preg_match("/Reply/i", $ping_output[2])===0){
echo "<font color='red'><strong>Offline!</strong></font>";
}
?>
</td>
</tr>
<?php
}
?>
</tbody>