How to fix ‘max=" " dynamical in script ’ error in PHP”? - jscript

php mysql
var strHtml11 = "rec_qty; ?>\" >
How to fix ‘max=" " dynamical in script ’ its not working error in PHP” ?

try this one
var strHtml11 = '<input name="weight[]" onkeyup="calculate(\'' + count + '\')" id="weight_"+count+" type="number" step="any" max="<?php echo $dd=$r1->rec_qty; ?>" required="required"/>';

Related

Add character between column combine in a CSV

I'm looking for the correct syntax to add some (") between my variable.
I need something like that :
"firstname","lastname","email","",""
Here is the first script I have :
foreach($line in Get-Content .\extract.csv)
{ $firstname = $line.split(';')[0]
$lastname = $line.split(';')[1]
$email = $line.split(';')[2]
$newLine = "$firstname - $lastname - $email"
echo $newLine }
I'm really new in scripting and I'm a bit lost with all these (') (")
My second question is : I need to extract my data only from the second row and ignore the first one, can you help me for this too ?
Thanks !
Have you try escaping your " and ' ?
In powershell you can use backtick ` (AltGr + 7) or doubling the char to do so :
Example :
Write-Host(" `" ")
Write-Host(" "" ")
Please add more code if this doesn't solve you issue !

how to remove the double quotes in output when i use echo command with "< >" (these charaters) in the string?

I wish to create a required no. of html divisions each with a different id (a series).
but when I write in a loop
echo "<div id=%prefix%%i%> %innerHTML% </div>" >> file.txt
It should be like
<div id=a1> x </div>
<div id=a2> x </div>
<div id=a3> x </div>
but it comes out to be
"<div id=a1> x </div>"
"<div id=a2> x </div>"
"<div id=a3> x </div>"
I have tried omitting the double quotes "" but then it throws an error due to the use of '>' (used to write in a file)
help me with this
An example as per Aacini's comment:
#Echo Off
Set "innerHTML=x"
Set "prefix=a"
(For /L %%A In (1 1 3) Do Set /P "=<div id=%prefix%%%A> %innerHTML% </div>"<Nul&Echo=)>"file.txt"
Pause
echo ^<escape them^>
this works absolutely fine.
echo ^<div id=%prefix%%i%^> %innerHTML% ^</div^> >> file.txt

Can't manipulate the string in powershell while calling the script in C# Windows Application

I am trying to take backup of SQL Server database using PowerShell and then making windows application around it. But it is not working. I think I have mingled up the strings by putting wrong double quotes and single quotes. Following is the code in C# where I am calling the PowerShell script.
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Import-Module SQLPS -DisableNameChecking");
pipeline.Commands.AddScript("$dt=Get-Date -Format '" + dtFormat + "' ");
pipeline.Commands.AddScript("$dbname = '" + dbName + "'");
pipeline.Commands.AddScript("$backup = " +bckFolderPath +#"\$($dbname)_db_$($dt).bak");
pipeline.Commands.AddScript("Backup-SqlDatabase -ServerInstance '" + serverName + "' -Database $dbname -BackupFile" + " $backup");
runspace.Close();
What can I do as this is not taking backup but if I run the script in PowerShell, then it is working.
You do realize that the commands you provided in your comment (that you say are working in PS) aren't the same as the ones you push through c#? The $backup line doesn't exist in your PS commands...
Anyway, I believe the error could be in the $backup line, missing quotes around the path...
pipeline.Commands.AddScript("$backup = '" +bckFolderPath +#"\$($dbname)_db_$($dt).bak'");

No such file or directory: exec of '/opt/lampp/cgi-bin/ failed PERL XAMPP Ubuntu

When I am running my CGI Perl script I am getting an error.
No such file or directory: exec of '/opt/lampp/cgi-bin/filename.cgi failed
I am using XAMPP on linux enviroment and this file exists in the root folder.
My Code:-
#!/usr/bin/perl
use diagnostics;
use DBI;
use strict;
use warnings;
use CGI qw(:standard);
my $driver = "mysql";
my $database = "mysql";
my $dsn = "DBI:$driver:database=$database";
my $userid = "root";
my $password = "password";
my $dbh = DBI->connect("dbi:mysql:dbname=mysql", "root", "password",
{ AutoCommit => 0,RaiseError => 1}, )
or die ("Couldn't connect to database: ") , $DBI::errstr;
my $sth = $dbh->prepare("select * from userrecords");
$sth->execute();
print "Content-type:text/html\r\n\r\n";
print "<a href='/Index.html'>-> Home Page</a>";
print "<table style='border-style: double; width: 30%;' border='1' cellpadding='1' cellspacing='1'>\n";
print "<td style='font-weight: bold' align='center'>Name</td><td style='font-weight: bold' align='center'>Address</td>
<td style='font-weight: bold' align='center'>City</td><td style='font-weight: bold' align='center'>Occupation</td><td style='font-weight: bold' align='center'>Age</td>\n";
while(my($ID,$name,$address,$city,$occupation,$age) = $sth->fetchrow_array) {
print " <tr>\n";
print " <td>$name</td>\n";
print " <td>$address</td>\n";
print " <td>$city</td>\n";
print " <td>$occupation</td>\n";
print " <td>$age</td>\n";
print " </tr>\n";
}
print "</table>\n";
$sth->finish();
$dbh->disconnect();
PLease help
Thanks in advance!!!
1/ The error message seems self-explanatory. It says that the file doesn't exist in '/opt/lampp/cgi-bin/'. You say that the file is in the root directory. It's probably just a question of moving the file to the correct directory.
2/ You are loading CGI.pm, but not using any of its features. Either use it (a good idea) or remove it.
3/ Once you get this file executing, you'll get the same "void context" errors as you mentioned in your previous question. We showed you how to fix that over there too.

How to correctly quote a subpattern placeholder when passing it in a variable?

I am having a problem correctly quoting the subpattern placeholder '$1' when passing it to the replacement operator 's///' in a variable. Could someone shed some light on this and advise me, what I am doing wrong?
I am exporting as set of MS Word documents to HTML files. This works more or less OK except that the files contain many cross references and these need to be fixed to keep working.
The exported references are in the form 'href="../../somefilename.docx"' and these need to be changed into 'href="somefilename.htm"' to reference the exported html files instead of the original Word files.
An example file test.htm could e.g. look like:
<html>
<body>
<a href="../../filename1.docx" />
<a href="../../filename2.docx" />
<a href="../../filename3.docx" />
<a href="../../filename4.docx" />
</body>
</html>
and the program execution should then yield:
<html>
<body>
<a href="filename1.htm" />
<a href="filename2.htm" />
<a href="filename3.htm" />
<a href="filename4.htm" />
</body>
</html>
I wrote me a little Perl program 'ReplaceURLs' to do that job. It works fine, if I "hardcode" the pattern and the replacement expressions (i.e. if I place the pattern directly into the s/.../.../g statement) - see variant 1.
But to make it more flexible I would like to allow those expressions to be passed in as argument (i.e. s/$pattern/$subst/g) and this I can't get that working. I can pass in the pattern in a variable - see variant 2, but not the substition value containing the subpattern reference $1.
In variant 3 for some reason the $1 in the substitution value is not recognized as a subpattern marker but treated as a literal '$'.
#!/usr/bin/perl
$debug = TRUE;
$tgtfilename = $ARGV[0] || die("usage: ReplaceURLs.pl <filename> <url-pattern> <url-substvalue>");
$urlpattern = $ARGV[1] || "href=\"\.\./\.\./(.*)\.docx\""; # href="../../(filename).docx';
$urlsubstval = $ARGV[2] || "href=\"\$1.htm\""; # href="$1.htm" --> href="(filename).htm";
print "replacing all occurences of pattern '$urlpattern' in file '$tgtfilename' with '$urlsubstval':\n";
# open & read $tgtfilename
open($ifh, '<', $tgtfilename) || die "unable to open $tgtfilename for reading: $!";
#slurp = <$ifh>;
$oldstring = "#slurp";
close($ifh) || die "can't close file $tgtfilename: $!";
if ($debug) { print $oldstring,"\n"; }
# look for $urlpattern and replace it with $urlsubstval:
# variant 1: works
#($newstring = $oldstring) =~ s!href=\"\.\./\.\./(.*)\.docx\"!href=\"$1.htm\"!g;
# variant 2: works
#($newstring = $oldstring) =~ s!$urlpattern!href=\"$1.htm\"!g;
# variant : does not work - why?
($newstring = $oldstring) =~ s/$urlpattern/$urlsubstval/g;
# save file
#open($ofh, '>', $tgtfilename) || die "unable to re-open $tgtfilename for writing";
#print $ofh $newstring,"\n";
#close($ofh) || die "can't close file $tgtfilename: $!";
# done
if ($debug) { print "result of replacement:","\n", $newstring,"\n"; } else { print "done."; }
__END__
If I run this using "perl ReplaceURLs.pl test.htm" I always get:
<html>
<body>
<a href="$1.htm" />
<a href="$1.htm" />
<a href="$1.htm" />
<a href="$1.htm" />
</body>
</html>
instead of the desired result. How do I need to quote or escape the '$1' in $urlsubstval to get this working?
M.
See perlop.
Options are as with m// with the addition of the following replacement specific options:
e Evaluate the right side as an expression.
ee Evaluate the right side as a string then eval the result.
r Return substitution and leave the original string untouched.
So, rather obscurely,
$ ls -1 | perl -pE '$str = q{"--$1--"}; s/(hah)/$str/ee;'
The solution by bobbogo only works, if the $str does not contain anything interfering with Perl's syntax. But because I wanted the replacement to contain something that by accident happens to look like a Perl assignment, namely 'href="$1.htm"', this yielded warnings 'Unquoted string "href" may clash with future reserved word ...' as well as errors 'Use of uninitialized value in substitution iterator at ..." and then crashed.
So, my finally working solution was to instead construct the command using proper string substitution and then to eval(...) that constructed command:
#!/usr/bin/perl
$debug = 1;
$tgtfilename = $ARGV[0] || die("usage: ReplaceURLs.pl <filename> [ <url-pattern> [ <url-substvalue> ] ]");
$urlpattern = $ARGV[1] || 'href="\.\./\.\./(.*)\.docx"'; # href="../../<filename>.docx"" in regexp format
$urlreplace = $ARGV[2] || 'href="$1.htm"'; # href="$1.htm" --> href="<filename>.htm";
print "replacing all occurences of pattern '$urlpattern' in file '$tgtfilename' with '$urlreplace':\n";
# open & read $tgtfilename
open($ifh, '<', $tgtfilename) || die "unable to open $tgtfilename for reading: $!";
#slurp = <$ifh>;
$oldstring = "#slurp";
close($ifh) || die "can't close file $tgtfilename: $!";
if ($debug) { print $oldstring,"\n"; }
# construct command to look for $urlpattern and replace it with $urlreplace:
$newstring = $oldstring;
$cmd = '$newstring =~ s!'.$urlpattern.'!'.$urlreplace.'!g';
# execute it:
if ($debug) { print "cmd=", $cmd, "\n"; }
eval($cmd);
# done
if ($debug) {
print "result of replacement:","\n", $newstring,"\n";
} else {
# save to file:
open($ofh, '>', $tgtfilename) || die "unable to re-open $tgtfilename for writing";
print $ofh $newstring,"\n";
close($ofh) || die "can't close file $tgtfilename: $!";
print "done.";
}
__END__

Resources