I am grabbing a .txt file and trying to reverse it, but I get this error when I try to, I don't understand it. Help please?
array_reverse() expects parameter 1 to
be array, string given in ......
Here is the code:
$dirCont = file_get_contents($dir, NULL, NULL, $sPoint, 10240000);
$invertedLines = array_reverse($dirCont);
echo $invertedLines;
A string is not an array? Even if it were (as in C strings) it would not work as you expected. You'll need to split the file on line breaks (if you're trying to reverse to get the end of the file first).
$invertedLines = array_reverse(preg_split("/\n/", $dirCont));
I think you need to pass the value on an array.
array_reverse(array($dircont));
This is working fine for me.
Related
Currently I am using the library jakubroztocil/rrule
When I convert a string containing EXDATE to rrule the origOptions attribute I get is always an empty object. But if I leave it out, it returns true.
Ex:
DTSTART;TZID=Asia/Saigon:20220808T080000\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;UNTIL=20220907T170000Z
With this string I get the correct result
DTSTART;TZID=Asia/Saigon:20220808T080000\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;UNTIL=20220907T170000Z\nEXDATE;TZID=Asia/Saigon:20220808T080000
With this string I get the wrong result
Looks like my problem will be something similar to #333
But I get nothing from it.
Thank u very much
Papa Parse seems wise, but I think he might be giving me null. I'm just:
Papa.parse(countries);
Where countries is a string containing the XMLHttpRequest of the countries csv file from a timezone database here:
https://timezonedb.com/download
But Papa Parse seems to have added an empty array to the end of it's data array. So when I'm searching and sorting through the array, that one empty guy at the end is giving me troubles. I can write around it but it's not ideal, and I thought Papa Parse was supposed to make those kind of csv parsing problems go away. Am I Parsing wrong?
Here is the end of the PapaParsed Array in console:
You need to use skipEmptyLines: true in parse config. For example:
Papa.parse(this.csvData, {skipEmptyLines: true,})
it was adding empty line to my iteration as well. i decided to skip it by doing loop:
for(let i=0;i<data.length -1;i++){
We can also use below syntax to remove empty lines from the record.
For example, in order to remove empty values from header, we can use the below code snippet.
headers.filter(Boolean);
I want to Verify text of AssignedAllUsers List can contains test1 or test2 but it should not contain test3
I am using following but not sure what is the problem with the code I am getting following error : AllAssignee.toContain is not a function
this.IncList = element.all(by.repeater("incident in $ctrl.allIncidents"));
this.AssignedAllUsers = this.IncList.all(by.css('[aria-label="Change assignee to "]'));
AssignedAllUsers.getText().then(function(AllAssignee){
console.log("AllAssignee = "+AllAssignee);
expect((AllAssignee.toContain(Logindata.Username0)) || (AllAssignee.toContain(Logindata.Username1)) && (AllAssignee.not.toContain(Logindata.Username2)));
});
Your error is a syntax issue. toContain belongs outside the value being tested, in other words outside of the first set of parentheses following your expect statement.
You have this:
expect((AllAssignee.toContain(Logindata.Username0)). You also have an extra set of parentheses, though I don't think that really matters.
You need to close the AllAssignee call, it should be: expect(AllAssignee).toContain(Logindata.Username0)
To answer your other question, there's no need to do it in one expect statement really. Since the list should never contain test3, thats your first assertion:
expect(AllAssignee).not.toContain(test3);
As for your other expected values, if you do not know which one will be present, just create an array and put both possible values inside of that. Then you can assert against the array to contain either test1 or test2:
var myArray = ['test1', 'test2'];
expect(myArray).toContain(AllAssignee);
Also see this related question about expecting items items in an array
Able to fix the problem with the code:
expect(AllAssignee).toContain('test1' || 'test2');
i had a code that c send back 1 number (mex)
the matlab code was
vMsg=unit32(Gateway_test_app(2))
now i added 1 more return value to Gateway_test_app(2) which is s STRING
what i need to do to get the two values back
i was thinking about something like this:
[vMsg,errMsg]=??????(Gateway_test_app(2))
what should i put in the ????? place?
thx for any help
johnny.
ps
using codegen and need not to get err when building
First call the function and store the two outputs, then run your extra function unit32 (what does it do, by the way?) on the first output only:
[vMsgOriginal, errMsg] = Gateway_test_app(2);
vMsg = unit32(vMsgOriginal);
This assumes that you don't want to process your new string output through your unit32 function.
I've research this topic extensibly and I'm asking as a last resort before assuming that there is no wildcard for what I want to do.
I need to pull up all the text input elements from the document and add it to an array. However, I only want to add the input elements that have an id.
I know you can use the \S* wildcard when using an id selector such as $(#\S*), however I can't use this because I need to filter the results by text type only as well, so I searching by attribute.
I currently have this:
values_inputs = $("input[type='text'][id^='a']");
This works how I want it to but it brings back only the text input elements that start with an 'a'. I want to get all the text input elements with an 'id' of anything.
I can't use:
values_inputs = $("input[type='text'][id^='']"); //or
values_inputs = $("input[type='text'][id^='*']"); //or
values_inputs = $("input[type='text'][id^='\\S*']"); //or
values_inputs = $("input[type='text'][id^=\\S*]");
//I either get no values returned or a syntax error for these
I guess I'm just looking for the equivalent of * in SQL for JQuery attribute selectors.
Is there no such thing, or am I just approaching this problem the wrong way?
Actually, it's quite simple:
var values_inputs = $("input[type=text][id]");
Your logic is a bit ambiguous. I believe you don't want elements with any id, but rather elements where id does not equal an empty string. Use this.
values_inputs = $("input[type='text']")
.filter(function() {
return this.id != '';
});
Try changing your selector to:
$("input[type='text'][id]")
I figured out another way to use wild cards very simply. This helped me a lot so I thought I'd share it.
You can use attribute wildcards in the selectors in the following way to emulate the use of '*'. Let's say you have dynamically generated form in which elements are created with the same naming convention except for dynamically changing digits representing the index:
id='part_x_name' //where x represents a digit
If you want to retrieve only the text input ones that have certain parts of the id name and element type you can do the following:
var inputs = $("input[type='text'][id^='part_'][id$='_name']");
and voila, it will retrieve all the text input elements that have "part_" in the beginning of the id string and "_name" at the end of the string. If you have something like
id='part_x_name_y' // again x and y representing digits
you could do:
var inputs = $("input[type='text'][id^='part_'][id*='_name_']"); //the *= operator means that it will retrieve this part of the string from anywhere where it appears in the string.
Depending on what the names of other id's are it may start to get a little trickier if other element id's have similar naming conventions in your document. You may have to get a little more creative in specifying your wildcards. In most common cases this will be enough to get what you need.