Can you add a variable to a file path? [duplicate] - php

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
PHP String Concatenation With Variables [duplicate]
(1 answer)
Concatenating strings retrieved from form $_Post in php
(1 answer)
php String Concatenation, Performance
(12 answers)
Concatenate HTML string and variable in PHP [closed]
(3 answers)
Closed 2 years ago.
I was wondering if you can add a variable to a file-path.
Example:
path: C:\\users\\john\\school\\hardware.properties";
I want to make a variable of the word preceding the . (dot) - in this case, "hardware" - so the user can write a name in a form and search/get another property.

You can just make it a string and add the var into it
$name = $_POST['name']
$path = "C:/.../".$name.".properties"

I just make more sure what Jasper B want to write:
In your form you have some submit input and text input.
You will get datas from inputs so you will just access them like:
$name = $_POST["name"];
After you just put $name variable to path like:
$path = "C:\users\john\school\".$name.".properties";

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.

How Can you add a variable inside do_shortcode("") [duplicate]

This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
PHP - concatenate or directly insert variables in string
(15 answers)
Closed 1 year ago.
So how would you add a variable inside a do_shortcode(''); Basically i have a variable holding a URL which is what I want to add inside the url attributte, but i am not sure how to do it.
This is what I tried so far
<?php echo do_shortcode('[evp_embed_video url='"'. $video .'"' preload="auto" template="mediaelement"]'); ?>
but of course, it didn't work. Any advice on how to properly format this?

String Function in PHP [duplicate]

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])

Split php value into two parts [duplicate]

This question already has answers here:
PHP: Split string [duplicate]
(7 answers)
Closed 1 year ago.
I want to split variable php value into two parts.
Inside a script that I use I load variables using this code:
{$searchResults.domainName}
The value is always defined like "domain name.com"
I want to splits this into two values
Before and after the dot, so I can load the value "domain" and the value ".com"
How can I achieve that with php?
You can use PHP explode for that:
$pieces = explode(".", $domainName);
/
$pieces[0] outputs 'domain'
$pieces[1] outputs 'com'
PHP Explode Manual

How could I construct a variable name from another variable? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Construct a PHP variable name based on other variable values and static text
$value = '200';
$_200 = 'other';
How could I echo the contents of the second variable, getting its name from the first variable? So basically read the value of $value, prepend an _ and use it as a variable name.
Same as always.
echo ${'_'.$value};

Categories