String Function in PHP [duplicate] - php

This question already has answers here:
PHP - Return everything after delimiter
(7 answers)
How to get everything after a certain character?
(9 answers)
get substring after delimiter
(3 answers)
Get the string after a string from a string
(5 answers)
Closed 3 years ago.
String Function in PHP:
$img = "WhatsApp Image 2019-11-18 at 17.15.42.jpeg | xyz.com/content/uploads/wcpa_uploads/image.jpg";
using string functions, how can I get complete text after | symbol, I mean only the complete url of image should be saved in variable.

There are several methods for that. If you do not want to regex or split to array, try this:
$path = trim(substr(strstr($img, "|"), 1));

Simplest way:
trim(explode('|', $img)[1])

Related

How to concatenate string with having single ,double quaotes or special characters in php? [duplicate]

This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Send PHP variable to JavaScript function [duplicate]
(6 answers)
How to pass php variable to JavaScript function as parameter
(4 answers)
how to pass php variable to javascript?
(2 answers)
Closed 12 months ago.
I am having one onclick event with some paramters with it. But in some
cases i am getting double quaotes or space between strings. so getting
error of Uncaught SyntaxError: missing ) after argument list or
invalid token.
How to overcome with this issue. I tried to use array and trim the
variables but it wont work for me.
$stringArray = ['string 1', 'string'2','001'];
$concatenated = trim(implode(',',$stringArray));
E.g: I am getting 3 string like :
$data1 = 'surgery';
$data2 = 'Cardio'c';
$data3 = 'hopsital ab"cc';
<a id='changeState' onclick=editModal(\"". $data1 ."\",\"". $data2 ."\",\"".$data3."\");>Click Here</a>
Please help to resolve this issue.

Get part of string PHP [duplicate]

This question already has answers here:
PHP - parse current URL
(6 answers)
Closed 2 years ago.
How to get a part of string using PHP?
I have a string like this.
https://test-app.com/admin/api/2019-10/orders.json?limit=2&page_info=eyJpZHMiOiIyMDY3MTczMTEzOTg3LDIwNjU0ODU0MzA5MTUsMjA2NTQ3OTI3MDUzMSwyMDYyODE3MzI5MjgzIiwibGFzdF9pZCI6MjA2NTQ4NTQzMDkxNSwibGFzdF92YWx1ZSI6IjIwMjAtMDMtMTcgMTg6MTc6NTkiLCJkaXJlY3Rpb24iOiJuZXh0In0
I want only the link.. like this
orders.json?limit=2&page_info=eyJpZHMiOiIyMDY3MTczMTEzOTg3LDIwNjU0ODU0MzA5MTUsMjA2NTQ3OTI3MDUzMSwyMDYyODE3MzI5MjgzIiwibGFzdF9pZCI6MjA2NTQ4NTQzMDkxNSwibGFzdF92YWx1ZSI6IjIwMjAtMDMtMTcgMTg6MTc6NTkiLCJkaXJlY3Rpb24iOiJuZXh0In0
That's not just a string it's a URL so use URL and path functions:
$parts = parse_url($str);
echo basename($parts['path']).$parts['query'];

How to decode Ascii code in a Character in PHP [duplicate]

This question already has answers here:
URL Decoding in PHP
(6 answers)
Closed 6 years ago.
I got the string in this format
solr/?key=color&facet=Blue%26keyword%3Dwoo
However, I want to get it in this format
solr/?key=color&facet=Blue&keyword=woo
Try urldecode:
$url = urldecode("solr/?key=color&facet=Blue%26keyword%3Dwoo");
// = solr/?key=color&facet=Blue&keyword=woo

Php, return portion of string before "0" [duplicate]

This question already has answers here:
How do I remove all specific characters at the end of a string in PHP?
(10 answers)
Closed 6 years ago.
I search PHP method for return portion of string before "0" has no number (1-9) after.
Example :
604000
I want to PHP script return :
604
Can you help me ?
Just use rtrim() as
$str="604000";
echo $str = rtrim($str, '0');

MYSQL Trim function using on PHP [duplicate]

This question already has answers here:
Php trim string at a particular character
(7 answers)
Closed 8 years ago.
I have a mysql codes which i need to do that trim and leading with PHP, anyone know how to write below logics with PHP code.
LEFT(TRIM(LEADING 'DHL ' FROM CONT_NAAM),20)
TRIM(LEADING 'DHL JVGL' FROM CONT_NAAM)
You can use preg_replace:
substr(preg_replace('/^(DHL )+/', '', $cont_naam), 1, 20)

Categories