Insert One Variable into Another with PHP [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to insert these $lat and $lng variable into the final $html variable with no success. Can somebody point me in the right direction?..
Much Appreciated.
<?php
$lat = '33.599968';
$lng = '-112.119499';
$url = 'http://maps.google.com/maps/api/staticmap? center=$lat,$lng&zoom=13&size=665x400&markers=color:red|$lat,$lng&sensor=false';
$html = '<img border="0" src="$url" width="665" height="400" border="1"></a>';
echo $lat;
echo $lng;
echo $url;
echo $html;
?>

two changes in the url line:
$url = "http://maps.google.com/maps/api/staticmap?center=$lat,$lng&zoom=13&size=665x400&markers=color:red|$lat,$lng&sensor=false";
" instead of ' so that php will evaluate $lat,$lng
And you want remove the space before center:
... staticmap? center ...
becomes
... staticmap?center ...

Strings delimited with double quotes " interpolate variables, strings delimited with single quotes ' do not. Use ".

Related

PHP find function without found element html [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to figure out how to grab the string inside H1 without actually H1 inside the string.
$html = "<div id="test"><h1>hello world</h1></div>"
foreach($html->find('div[id=test] h1') as $test1){
echo '<div>';
echo $test1;
echo '</div>';
}
$test1 returns "<h1>hello world</h1>"
I'd like for $test1 to be just "hello world" and without the h1 tags. Thank you in advance
You can use regex for this:
$str = '<div id="test"><h1>hello world</h1></div>';
$matches = array();
preg_match('/<h1>(.*)<\/h1>/', $str, $matches);
echo $matches[1];
Outputs: hello world
Docs:
http://www.php.net/preg_match
Demos:
https://eval.in/78867
http://regex101.com/r/lG3dO8

Access to POST vars in php with string name [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi, I have a problem when try access to $_POST vars in php. I have a combo with this name "c012". Well, I send the form with this var, and I have checked this var is send ok, and when I try access with this code, where $var1, $var2 and $var3 are numbers:
$var1 = 0;
$var2 = 1;
$var3 = 2;
$pointer_combo = "c".$var1.$var2.$var3;
echo $_POST['$pointer_combo'];
Don't show anything, but if I try this:
echo $_POST['c012'];
Works, and show the value. Whats the problem with code above?
If you are using a dynamic index (index value stored in a variable), you don't need the quotes.
Try this:
echo $_POST[$pointer_combo];
PHP won't do variable substitution if the value is in single quotes. Only double quotes or no quotes. So
echo $_POST[$pointer_combo];
Would work, as would:
echo $_POST["$pointer_combo"];
(But obviously in that second example there isn't much point in the quotes being there!)
Lose the quotes:
$_POST[$pointer_combo];

Remove specific match from a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to remove a particular match of characters from a string.
For example i have strings;
topics-p10-new-model-cars
topics-p20-new-model-cars
topics-p30-new-model-cars
topics-p40-new-model-cars
Then i need the results as,
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
That means i want to remove p10-,p20-,etc..
.Those are the page numbers. It may be any number..
How can i do this..? Thanks in advance
Try this:
$result = preg_replace('/\-p\d+/', '', $string);
Note: I'm assuming that the string format does not change (I mean this [topics-p10-new-model-cars]). If my assumption is right.
Then you can do this
if (textBox1.Text.Contains("-p10-"))
{
//topics-p10-new-model-cars
String[] splited = textBox1.Text.Split(new char[] {'-'});
String rString = String.Format("{0}-{1}-{2}-{3}",
splited[0],splited[2],splited[3],splited[4]);
MessageBox.Show(rString);
}
//OR This method
if (textBox1.Text.Contains("-p10-"))
{
String result = textBox1.Text.Replace("p10-", "");
MessageBox.Show(result);
}
With 'preg-replace'::
For, example:
<?
echo preg_replace('/p[0-9]+\-/', '', 'topics-p10-new-model-cars');
?>
Follow this link:
http://www.php.net/manual/en/function.preg-replace.php

Variable Not Working With Glob Function In Php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
foreach(glob($select)) as $filename){
echo $filename;
echo "<a class='vlightbox1' href='$filename' title='$filename'><img src='$filename' style='height:120px; width:160px; alt='$filename'></a>";
echo "<a href='ap_deleteimages.php?id=$filename'>Delete</a>";
}
It is not working Properly. I Have Added $select Value as under
$select=document.write(document.getElementById('flist').value)
and 'flist' is a option tag id in html and glob function do not work with it
foreach(glob($select) as $filename){
echo $filename;
echo "<a class='vlightbox1' href='$filename' title='$filename'><img src='$filename' style='height:120px; width:160px; alt='$filename'></a>";
echo "<a href='ap_deleteimages.php?id=$filename'>Delete</a>";
}
You have the syntax error at glob function in your code. The right syntax is in above code.
Second thing is that glob() is used to find all the search pathname matching a pattern. So you need to check that the value of $select is correct or not.
Read more above glob() function.
How about putting in the parentheses?
foreach ( glob($select) as $filename)

Trim string after and before a character [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to trim this string after "=" and before ";"
com=8af14f8b9d5be16e807ab9e0ed1d7edb:b6668c681f9d3bd2ad4ae31a8b6c7f2859939a75;
so that it echoes 8af14f8b9d5be16e807ab9e0ed1d7edb:b6668c681f9d3bd2ad4ae31a8b6c7f2859939a75
You can use the str_replace function to replace multiple values by, in this case, nothing:
str_replace(array('com=', ';'), '', $string);
This can also work:
parse_str(trim(
'com=8af14f8b9d5be16e807ab9e0ed1d7edb:b6668c681f9d3bd2ad4ae31a8b6c7f2859939a75;'
, ';'));
echo "$com\n";
Try this:
$value="aaaacom=8af14f8b9d5be16e807ab9e0ed1d7edb:b6668c681f9d3bd2ad4ae31a8b6c7f2859939a75;";`
$pos=strpos($value,"=");
echo substr($value,$pos+1,strlen($value)-($pos+2));
You can use a regex:
$str = 'com=8af14f8b9d5be16e807ab9e0ed1d7edb:b6668c681f9d3bd2ad4ae31a8b6c7f2859939a75;';
echo preg_replace('/([a-z]+)=(.*);/', '\2', $str);
But it looks like a .ini file, then maybe you want this:
Try this:
$ini = 'com=8af14f8b9d5be16e807ab9e0ed1d7edb:b6668c681f9d3bd2ad4ae31a8b6c7f2859939a75;';
$parsed_ini = parse_ini_string($ini);
echo $parsed_ini['com'];

Categories