I've got some problems with my url on my website. I'm trying to get a link with the given GET parameters, but i'm getting my previous parameter aswell.
My url looks like this:
www.cdwinkel.dev/search-results?genre=Pop&medium=DVD&medium=Single .
It should be:
www.cdwinkel.dev/search-results?genre=Pop&medium=Single .
I'm running the following code:
$data['url'] = createurl();
function createurl(){
$i = 1;
$string = "?";
$keys = array_keys($_GET);
foreach($_GET as $get){
if($get != ""){
$string .= $keys[$i] . "=" . $get ."&";
$i++;
}
}
$string = rtrim($string, "&");
return $string;
}
$i = 1, because my first value in my array is empty.
And my button looks like this:
<a href='".$data['url'].'&medium='.$names[$i]."'>
I guess I should'nt set &medium=.$names[$i] in the href tag,
but I wont get the new $names[$i] in my function, so I won't get a new url if i wont add it in.
I'm looking forward to your responce.
Sincerely,
Kars Takens
At this point i've created an array with the right arraykeys and values.
$url = array_slice($_GET, 1);
This returns the following array:
array (size=2)
'genre' => string 'Pop' (length=3)
'medium' => string 'DVD' (length=3)
After this I decoded this into a new string:
genre=Pop&medium=DVD
I got 6 button which I created in a foreach loop, but i'm getting &medium='VALUE' Twice. This only happens after the first time. So the first time my button works well.
<?php
$names = array_keys($data['tellen']);
$i = 0;
foreach($data['tellen'] as $m){
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}
Hopefully you can help me further with this information.
I solved my problem by adding this in my forloop:
foreach($data['tellen'] as $m){
if(isset($_GET['medium'])){
unset($_GET['medium']);
$url = array_slice($_GET, 1);
$data['url'] = urldecode(http_build_query($url));
}
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}
initially I have to state, that I have little to no experience with powershell so far. A previous system generates the wrong output for me. So I want to use PowerShell to change this. From the System I get an output looking like this:
TEST1^|^9999^|^Y^|^NOT IN^|^('1','2','3')^|^N^|^LIKE^|^('4','5','6','7')^|^...^|^Y^|^NOT IN^|^('8','9','10','11','12')
TEST2^|^9998^|^Y^|^NOT IN^|^('4','5','6')^|^N^|^LIKE^|^('6','7','8','9')^|^...^|^Y^|^NOT IN^|^('1','2','15','16','17')^|^Y^|^NOT IN^|^('18','19','20','21','22')
When you look at it, there is a starting part for each line (TEST1^|^9999^|^) followed by a1 to a-n tuples (example: Y^|^NOT IN^|^('1','2','3')^|^).
The way I want this to look like is here:
TEST1^|^9999^|^Y^|^NOT IN^|^('1','2','3')
TEST1^|^9999^|^N^|^LIKE^|^('4','5','6','7')
TEST1^|^9999^|^Y^|^NOT IN^|^('8','9','10','11','12')
TEST2^|^9998^|^Y^|^NOT IN^|^('4','5','6')
TEST2^|^9998^|^N^|^LIKE^|^('6','7','8','9')
TEST2^|^9998^|^Y^|^NOT IN^|^('1','2','15','16','17')
TEST2^|^9998^|^Y^|^NOT IN^|^('18','19','20','21','22')
So the tuples shall be printed out per line, with the starting part attached in front.
My solution approach is the AWK equivalent in Powershell, but to date I lack the understanding of how to tackle the issue of how to deal with an indetermined number of tuples and to repeat the starting block.
I thank you so much in advance for your help!
I'd split the lines at ^|^ and recombine the fields of the resulting array in a loop. Something like this:
$sp = '^|^'
Get-Content 'C:\path\to\input.txt' | % {
$a = $_ -split [regex]::Escape($sp)
for ($i=2; $i -lt $a.length; $i+=3) {
"{0}$sp{1}$sp{2}$sp{3}$sp{4}" -f $a[0,1,$i,($i+1),($i+2)]
}
} | Set-Content 'C:\path\to\output.txt'
The data looks quite regular so you could loop over it using | as the delimiter and counting the following cells in 3s:
$data = #"
TEST1^|^9999^|^Y^|^NOT IN^|^('1','2','3')^|^N^|^LIKE^|^('4','5','6','7')^|^Y^|^NOT IN^|^('8','9','10','11','12')
TEST2^|^9998^|^Y^|^NOT IN^|^('4','5','6')^|^N^|^LIKE^|^('6','7','8','9')^|^Y^|^NOT IN^|^('1','2','15','16','17')^|^Y^|^NOT IN^|^('18','19','20','21','22')
"#
$data.split("`n") | % {
$ds = $_.split("|")
$heading = "$($ds[0])|$($ds[1])"
$j = 0
for($i = 2; $i -lt $ds.length; $i += 1) {
$line += "|$($ds[$i])" -replace "\^(\((?:'\d+',?)+\))\^?",'$1'
$j += 1
if($j -eq 3) {
write-host $heading$line
$line = ""
$j = 0
}
}
}
Parsing an arbitary length string record to row records is quite error prone. A simple solution would be processing the data row-by-row and creating output.
Here is a simple illustration how to process a single row. Processing the whole input file and writing output is left as trivial an exercise to the reader.
$s = "TEST1^|^9999^|^Y^|^NOT IN^|^('1','2','3')^|^N^|^LIKE^|^('4','5','6','7')^|^Y^|^NOT IN^|^('8','9','10','11','12')"
$t = $s.split('\)', [StringSplitOptions]::RemoveEmptyEntries)
$testNum = ([regex]::match($t[0], "(?i)(test\d+\^\|\^\d+)")).value # Hunt for 1st colum values
$t[0] = $t[0] + ')' # Fix split char remove
for($i=1;$i -lt $t.Length; ++$i) { $t[$i] = $testNum + $t[$i] + ')' } # Add 1st colum and split char remove
$t
TEST1^|^9999^|^Y^|^NOT IN^|^('1','2','3')
TEST1^|^9999^|^N^|^LIKE^|^('4','5','6','7')
TEST1^|^9999^|^Y^|^NOT IN^|^('8','9','10','11','12')
When I check with the FETCH command, I get like this:
2148 FETCH (UID 2159 INTERNALDATE "06-Nov-2013 06:36:15 +0000" RFC822.SIZE 3702 ENVELOPE ("Wed, 6 Nov 2013 12:06:39 +0530" {19} Reg: "test subject" (("karthick kumar" NIL "ngkarthick" "aroxo.com")) (("karthick kumar" NIL "ngkarthick" "aroxo.com")) (("karthick kumar" NIL "ngkarthick" "aroxo.com")) ((NIL NIL "phpkarthick" "gmail.com")) NIL NIL NIL ""))
There is some thing unwanted {19} in fetch command
The {19} followed by a CRLF is called a literal. It says the next 19 characters are to read and fetched without any additional interpretation. They are part of the IMAP protocol, and they are one way that strings with difficult characters can be transferred. They are used to transmit bodies, usually, since they tend to have CRLFs of their own.
In this case, the server has decided to transfer the subject like this, so it doesn't have to escape the quotes, that would otherwise be significant to the protocol.
Perhaps your library is not entirely protocol compliant?
i had solved this issue by doing some pattern replace and successfully resolved and fetch all Email ,
below are my code which help me achive this
please add this code to fMailbox.php after the line
$output = array();
line no nearly 1117
$response = $this -> write('FETCH ' . $messages . ' (UID INTERNALDATE RFC822.SIZE ENVELOPE)');
$hintter = implode(' ', $response);
$pattern = '(\{[0-9]+\})';
if (preg_match($pattern, $hintter, $match)) {
$responses = preg_replace($pattern, '', $response);
$responsesnew = array();
$i = 0;
$j = 0;
foreach ($responses as $reps) {
if (substr(trim($reps), 0, 1) != '*') {
$responsesnew[$i] = $responses[$j - 1] . $reps;
$i++;
}
$j++;
}
} else {
$responsesnew = $response;
}
and change the foreach parameters to
foreach ($responsesnew as $line)
from
foreach ($responsesnew as $line)
I'm getting this post object from Facebook api :
{
"id"=>"XXX",
...,
"message"=>"abcd efg hijkl mn The New York Times opqr",
"message_tags"=>{
"18"=>[{
"id"=>"5281959998",
"name"=>"The New York Times",
"type"=>"page",
"offset"=>18,
"length"=>18
}]
},
...
}
How can I make a link in rails to facebook page like using offset & length attributes ? Result would be like this :
abcd efg hijkl mn The New York Times opqr
I had to do this just now, but in PHP. This was my solution:
/**
* Get message HTML
*
* #param string $text The message text
* #param array $tags The tags array
* #return string HTML message string with linked tags
*/
public static function getMessageHtml($text, $tags) {
$doc = new DOMDocument;
$doc->appendChild($doc->createTextNode($text));
if (is_array($tags)) {
foreach ($tags as $tag) {
$tag = $tag[0];
$start = 0;
foreach ($doc->childNodes as $child) {
if ($tag['offset'] < $start + strlen($child->nodeValue)) {
$meat = $child->splitText($tag['offset'] - $start);
$tail = $meat->splitText($tag['length']);
$a = $doc->createElement('a');
$a->setAttribute('href', '//facebook.com/' . $tag['id']);
$a->setAttribute('title', $tag['name']);
$meat->parentNode->replaceChild($a, $meat);
$a->appendChild($meat);
break;
}
$start += strlen($child->nodeValue);
}
}
}
return trim($doc->saveHTML());
}
This has worked in all my test cases so far, but it may be dodgy if tags overlap or are nested. I'm not sure if Facebook ever returns tags like that.
Hopefully you can easily port this to Ruby.
Is it possible in PowerShell to add a parameter on a cmdlet call ONLY if there is a variable to pass?
E.g.
Send-MailMessage -To $recipients (if($copy -ne "") -cc $copy) ....
Not the way you've written above but you can splat the parameters, building the hash with conditions, so you only have one call to send-mailmessage. An example from a script I wrote a few months ago:
#Set up default/standard/common parameters
$MailParams = #{
"Subject"="This is my subject";
"BodyAsHtml" = $true;
"From" = $MailFrom;
"To" = $MailTo;
"SmtpServer" = $SMTPServer;
};
#On the last day of the month, attach a logfile.
if ((Get-Date).AddDays(1).Day -eq 1) {
$attachment = $LogFilePath;
$ReportContent = "Full log for the the preceding month is attached.<br><br>" + $ReportContent;
$MailParams.Add("Attachments",$attachment);
}
send-mailmessage #MailParms
So in your case, it would be:
$MailParams = #{
"Subject"="This is my subject";
"From" = $MailFrom;
"To" = $recipients;
"SmtpServer" = $SMTPServer;
};
if (($copy -ne [string]::empty) -and ($copy -ne $null)) {
$MailParms.Add("CC",$copy);
}
send-mailmessage #MailParms