I am trying to find a way to create a simple dynamic URL, that gets its information from boxes where people enter something.
I got a google search machine and want to refer to it, so basically I wanted two boxes:
One for choosing which directory to search in (the google machine has different directories in its index I want people to be able to choose from those)
and the other for the search term they are looking for.
The URL looks like that:
http://searchengine.xx/search?q=SEARCHTERM&site=DIRECTORY&btnG=Suchen&entqr=0&ud=1&sort=date%3AD%3AL%3Ad1&output=xml_no_dtd&oe=UTF-8&ie=UTF-8
I tried it with PHP like that:
<?php
$directory = $_GET['searchterm'];
echo "http://searchengine.xx/search?q=".$searchterm."&site=directory&btnG=Suchen& entqr=0&ud=1&sort=date%3AD%3AL%3Ad1&output=xml_no_dtd&oe=UTF-8&ie=UTF-8'>URL</a>
?>
This doesnt seem to work well and I wondered if this was possible in any other way (simple HTML, JavaScript maybe?)
try to mix php and htaccess...
<?php
//get the text form the text box and put it in a variable eg.($text)
$url = 'index.php?searchterms=$text';
header("Location: $url");
?>
I think that something like this might work.
Get the text from the text box, then put the text onto a variable (i've used $text to exemplify).
Put the url that you want in a variable (i've used $url to exemplify), but in the end of the url put the text variable the way i did it.
Finally, use the header function to redirect to the url that you want.
Hope i helped
There are several problems with the PHP code in your question. $searchterm is never set and the echo statement is never ended. Try this instead:
<?php
$searchterm = $_GET['searchterm'];
$searchterm = strip_tags($searchterm);
echo "<a href='http://searchengine.xx/search?q=".$searchterm."&site=directory&btnG=Suchen&entqr=0&ud=1&sort=date%3AD%3AL%3Ad1&output=xml_no_dtd&oe=UTF-8&ie=UTF-8'>URL</a>";
?>
The strip_tags will ensure " and ' are removed so it doesn't break your link.
Related
I am using the following code:
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try one of the navigation links above or a search? Or it is possible you are trying to access a restricted page without being logged in to gain access.', 'shapely' ); ?></p>
Which ends up being displayed as follows:
It looks like nothing was found at this location. Maybe try one of the navigation links above or a search? Or it is possible you are
trying to access a restricted page without being logged in to gain
access.
What I want to display is this:
It looks like nothing was found at this location.
Maybe try one of the navigation links above or a search?
Or it is possible you are trying to access a restricted page without
being logged in to gain access.
So what I want is a way to break the line. I tried <br /> and \n, and neither work. Is there a way to add line breaks in the esc_html_e() function?
I know this a older question, I wanted to to point out that there is no need to use the output buffering functions in PHP. You can simplify this code by calling the WordPress function esc_html__() instead of esc_html_e(). This function will return the escaped value instead of echoing it out.
https://developer.wordpress.org/reference/functions/esc_html__/
echo nl2br( esc_html__("Line1\nLine2\nLine3", 'shapely') );
First off you can't use \n inside single quotes. Also, line breaks won't be rendered as such on on a webpage. From the looks of things esc_html_e() actually echoes the output so to capture & process it you'd need to do something like this:
ob_start();
esc_html_e("Line1\nLine2\nLine3");
$output = ob_get_contents();
ob_end_clean();
echo nl2br($output);
But this seems like an awful lot to go through and probably the wrong way to go about it. If you need to output html you probably don't be using esc_html_e() to begin with. Really hard to say without more context.
We're completely redoing our website, and putting most of our pages into a new CMS (Adobe cq5- on server
1). However, we have some php/mysql pages that cant go in there, so we are housing them on our own server(server2). I need our pages on server2 to look exactly like the page on server1.
There is a template on Server 1, with a url of:
http://staging-cms.com/content/directory/template.html
So, I need to
1.pull the template from Server1 using the above URL.
2.Look in that template for this div:
<div class="text"><p>CONTENT FOR TEMPLATE GOES HERE.<br></p></div>
3.Take the content of the page on server 2 and insert it at the above point.
4. Return the full page, with template and contents onto a page on server2.
So, the final url would be something like:
http://server2.com/books.php
Is this possible?
I've tried this below, but all I get is a page with
databases.php printed.
$Content = file_get_contents("http://staging-cms.uc.edu/content/libraries /template.html");
$Content = str_ireplace('CONTENT FOR TEMPLATE GOES HERE','databases.php','What goes here??');//staging-cms.uc.edu/content/libraries/template.html);
print ($Content);`
I've tried other things where I can return the template (kind of). But I cant seem to get it all working together?
$template = file_get_contents("http://staging-cms.uc.edu/content/libraries/template.html");
list($top, $bottom) = explode('CONTENT FOR TEMPLATE GOES HERE', $template);
echo $top;
include '/path/to/databases.php';
echo $bottom;
The PHP code in databases must actually be executed before displaying to the user, so you can't use str_ireplace(), this deals with literal strings only, not file names or PHP code.
Instead you need to split the template into 2 parts (top and bottom), and then include the PHP code which will be executed.
I highly recommmend explode(); function. If you have have the exact text "CONTENT FOR TEMPLATE GOES HERE." your code will be something like this.
<?php
$Content = file_get_contents("http://template.url");
$PHPFileContent = file_get_contents("/path/to/databases.php");
$explodedContent = explode("CONTENT FOR TEMPLATE GOES HERE", $Content);
$theFinalContent = "$explodedContent[0] $PHPFileContent $explodedContent[1]";
?>
You need to search how explode() works btw.
Hope helps.
One Good Design Patters that i like to use is that:
$new_file = file_get_contents($file_for_future);
$old_file = file_get_contents($file_to_copy_body);
preg_match('\preg to find the right position\', $new_file,$match, PREG_OFFSET_CAPTURE);
reg pattern can be '\div class=\"text\">\' but is untested, do it yourself.
$pos = $match[0][1];
The third and forth command is for find the right position that you want to put your new code inside the new file, is a INT number and should be the exact point that you want to start writing your old code.
PREG_OFFSET_CAPTURE in the preg_match force the regular expression to say where they find the standart.
And the magic is:
$final_file = substr($new_file, 0, $pos)."\n".$old_file."\n".substr($new_file, $pos);
This logic will generate a file, using the new template, inserting the old code right where you want to put it.
I want to show on my site an element depending on my site's url.
Currently i have the following code:
<?php
if(URL matches)
{
echo $something;
}
else
{
echo $otherthing;
}
?>
I wanted to know how do I get the URL on the if condition, because I need to have only one php archive to show on many diferent pages
EDIT: The solution provided by Rixhers Ajazi doesnt work for me, when i use ur code i get the same URI for both of my pages, so the if sentence always goes by the else side, is any way to get the exact string u can see on the browser to the PHP code
http://img339.imageshack.us/img339/5774/sinttulocbe.png
This is the place where it changes but, the URL i get on both sides is equal, im a little bit confused
To get the URL, use:
$url = http://$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
Use following syntax with URL
http://mysite.com/index.php?var1=val&var2=val
Now you can get the values of variables in your $_GET variable and use in if condition like
if($_GET['var1'])
You can do so by using the $_SERVER method like so :
$url = $_SERVER['PHP_SELF']; or $url = $_SERVER['SERVER_NAME'];
Read up on this more here
if($url == 'WHATEVER')
{
echo $something;
}
else
{
echo $otherthing;
}
?>
You can use different variables, e.g., $_SERVER["PHP_SELF"], or $_SERVER["REQUEST_URI"]. The first one contains the path after the server name and until a possible ? in the URL (the part with the GET parameters is excluded). The second one contains also the GET parameters. You can also retrieve the hostname used to connect to the server (in case you have a virtual host situation) using $_SERVER["HTTP_HOST"]. Therefore by concatenating all these you can reconstruct the full URL (if you really need it, maybe the script name is enough).
How do i change a url in a string example :
This is a link http://google.com.au
To something like this
This a warning page link http://google.com.au
EDIT:
What i'm trying to do is take a description entered by the end user, They might enter links in the description, i want to change all the links to make them GOTO a warning page, the warning page is ./warn.php?site=link
The string might look like this
This is a awesome description Google and this another link Google images
Ok here's what i tried:
$descc = mysql_real_escape_string($_POST['description']);
$descc = preg_replace('"\b(http://\S+)"', '$1', $descc);
Check this, although im not sure if you are really refering to this, just let me know the case then ---
$mylink = "http://google.com.au";
This a warning page link http://google.com.au
EDIT version 1.0
Even it is on description box data you can fetch it via jquery or php like
$mylink = $_GET['desc_name_data'];
Please be more specific with the problem :)
EDIT Version 1.1
Check this and let me know then --
echo preg_replace('(<a href="http://\S+)', '<a href="./warn.php?site='.'google.com.au'.'">google.com.au', $descc);
I'm not sure I understand your question, but urlencode may help.
http://google.com.au
If this isn't it, then please be a bit more specific with what you're trying to achieve and what you have tried.
EDIT:
Ok, you could try a HTML parser to extract the href from the link, then rewrite appropriately. This is likely to be more reliable that a regex.
You should still add urlencode if you're passing a url as a querystring.
You could have a look at preg_replace().
Probably another basic question but its been annoying me for a while now...
I have a php file which is included on a php web page to bring in dynamic content from my mysql database.
Everything works fine with this except when i try get pictures to work and here is the problem.
I am using the code:
echo "<img src=fishery_images/$region/$url/$url1.jpg'/>";
All of which has been selected from the correct table and so on. an example of what i want this to resolve to is below:
fishery_images/fife/goldenloch/goldenloch1.jpg
However because i have the code:
$url1.jpg
and $url1 is not defined as anything then it resolves as the following:
fishery_images/fife/goldenloch/.jpg
i can have anything from goldenloch1.jpg all the way to goldenloch10.jpg so need to be able to say which image should be used.
how is it i say $url1.jpg without meaning $url1?
Really hope this makes sense... and thanks in advance
echo "<img src=fishery_images/{$region}/{$url}/{$url}1.jpg'/>";
http://en.wikipedia.org/wiki/String_interpolation#PHP
You'll want to use curly braces to wrap your variable:
echo "<img src=fishery_images/$region/$url/{$url}1.jpg'/>";