strpos() / stripos() bug or expected behavior? - preg-match

I'm trying to check if <script or <link is in a string.
if (stripos($string, '<script') !== FALSE || stripos($string, '<link') !== FALSE)
The code above never finds the match unless I take out the < Do I need to escape that character or something? I tried preg_match('~\b<script\b~',$string) and that failed as well.
I'm sure I'm missing something simple. Any help is greatly appreciated.
Thanks in advance
UPDATE: str_ireplace(array('<script','<link'), array('<replacescript','<replacelink'), $string) does not work either

Related

Laravel whereRaw - how to escape a '?'

Is there a way to escape a "?" in a eloquent whereRaw Statement? (Using laravel 6.x)
example:
ExampleModel::whereRaw(' "table"."json_field"::jsonb ?| array[\'test\', \'test2\'] ')->get();
This gets sent to the db as
where "table"."json_field"::jsonb $1| array['test', 'test2']
And well, thats not what i wanted to query...
Tried with '\?', put it in a binding (Laravel doc) - still no success.
Also i didn't find a reference in the docs ...
In my Usecase i want it to compare a json object with the psql comparing "?|" (Postgres Doc)
Thanks in advance!
the question is pretty old but my answer might help anyway.
The solution is very simple: just escape the questionmark with another questionmark.
The code of your example would look like this:
ExampleModel::whereRaw(' "table"."json_field"::jsonb ??| array[\'test\', \'test2\'] ')->get();
This solution has been tested with Laravel 7.28.3.
Didn't test but try using PDO:
$whereRaw = DB::connection()->getPdo()->quote(' "table"."json_field"::jsonb ?| array["test", "test2"] ');
ExampleModel::whereRaw($whereRaw)->get();
Well, didn't find an answer, but a workaround:
Don't use the question mark operators!
Instead i went for the named function. I found the named function via
SELECT
oprname,
oprcode || '(' || format_type(oprleft, NULL::integer) || ', '
|| format_type(oprright, NULL::integer) || ')' AS function
FROM pg_operator
WHERE oprname = '?|';
( Found there: big thanks to this guys post!)
So my Eloquent query now looks like:
ExampleModel::whereRaw('jsonb_exists_any("table"."json_field"::jsonb, array[\'test\', \'test2\'])')->get();
At least its working ¯\_(ツ)_/¯

if query returning a return error laravel

I need some help with this query, I don't understand why am I getting this error "Parse error: syntax error, unexpected 'return'(T_RETURN)" even though my previous line was working. I checked on other question similar to this error and see if I have similar mistake but I don't think so, I even double checked to see if I am missing any bracket in my query. Can someone please help me? Thanks a lot.
This part of the code work, "if(count($data)>0){" but when I changed to this it doesn't work anymore " if (hire::where('hire_status','Yes'->count($data) > 0){"
Controller:
public function getHire(){
$data['data'] = DB::table('personal_infos')->where('deleted_at',NULL)->get()->sortByDesc('created_at');
if (hire::where('hire_status','Yes'->count($data) > 0){
// if(count($data)>0){
return view('hire',$data);
}else{
return view('hire');
}
Missing closing parenthesis ).
if (hire::where('hire_status','Yes'->count($data) > 0){
if (hire::where('hire_status', 'Yes')->count($data) > 0) {

Prestashop: Undefined Smarty variables in order-detail.tpl

In order-detail.tpl, there are variables such as {$is_guest} and {$return_allowed}. A little debugging (using Javascript alert) shows that {$is_guest} is undefined for some reason and {$return_allowed} returns 0 even though I allowed returns. This is leading to the order-detail page hiding merchandise return section.
All these Smarty variables are defined in root/controllers/OrderDetailController.php, so I don't know what's causing the errors.
I'm using Prestashop 1.4.9. Any help is greatly appreciated. Thank you!
I solved my own question. Go to root/controllers/OrderDetailController.php. Around line 144, change
'is_guest' => false,
to
'is_guest' => "false",
And also, change
{if !$is_guest}
to
{if $is_guest == "false"}
As for $return_allowed, it turns out that the items must be marked as delivered first in the BO. It is defined such that it is false unless paid for + delivered + before return deadline.

Label must be a simple identifier?? Flash/Flex Builder

I have this code:
public function chooseCategoryDDL_changeHandler(event:IndexChangeEvent):void {
var para:Object = new Object();
para.action = "changecategoryxml";
para.book_class = event:IndexChangeEvent.book_class;
if (event.IndexChangeEvent > -1 ) {
changeCategory.send(para);
}
I keep getting the error message that, 'Label must be a simple identifier'. Ideally, i'm wanting to write the code to state:
... para.book_class = event.selectedItem.book_class;
if (event.selectedItem > -1 ) {
changeCategory.send(para);
}
Though, when I try and use the selectedItem syntax, it gives me an 'Access to undefined property selectedItem'. I'm really tearing my hair out about this and it's been bugging me for ages. If anyone can please shed any light on this I will be eternally grateful :)
Thanks
I had the same error from a dumb typo : some line was terminated by ':' instead of ';'
For the visually impaired (like me), that's colon instead of semicolon.
I didn't really read this, but the syntax of this line looks invalid:
para.book_class = event:IndexChangeEvent.book_class;
Use a dot maybe?
para.book_class = event.IndexChangeEvent.book_class;

Smarty issues with Fckediter

I'm new to this forum , i hope u do not mind questions even if its stupid.
i m trying to post a value from the fckeditor embedded in smarty template.The value submitted is,
a
b
c
d
however when echo the posted value i get ,
a b c d
which is very irritating because i want the actual value submitted.
No matter whatever i do i only see text with these tags i do not understand if have to do any configuration in smarty or fckeditor or what ?
Please help with this any help will be greatly appreciated.
i will appreciate your help
Mukesh ?
It was just that my framework used was sanitizing all GET,POST requests.
Then removed those function that was causing the function and job done .
function sanitize($data)
{
$data = trim(strip_tags($data, "<a><b><strong><em><i><u><br><h3><h4><h5>"));
return $data;
}

Resources