I have a headbreaking question on one of my projects. I want to render a specifications div from an another website into mines (I've permission).
It concerns the following website: http://www.gsmarena.com/htc_one_x-4320.php
The div: <div id="specs-list"></div>
Now I have the following code:
<?php
function get_content_part($part=null, $website = null)
{
$website = file_get_contents($website);
$data = str_replace("\n", '', $website);
echo preg_match("/\<div class\=\"'.$specs-list.'\"\>(.*)<\/div\>/",$data,$match);
return $match;
}
?>
But because the link is different with every product, I made a custom field within wordpress. The URL renders with the following code:
<?php echo(types_render_field("gsmlink", array("alt"=>"gsmlink","proportional"=>"true"))); ?>
This renders a completely clean source code, only the text.
Now I seriously have NO idea where I've to put this data so the script knows which URL and which div. Can someone help me with this?
Related
I'm building a simple tool that generates some custom HTML based on data from the website.
After, we can simply publish this content to a Facebook page via the Facebook SDK (API).
The following PHP code is an excerpt of how the $content is set up:
$content = '';
$content .= '📍 The address<br>';
$content .= '🛀 2 bathrooms<br>';
Via some AJAX code, this $content is shown as HTML in a div on the page, where the user can further edit the texts.
Then, the user can click on 'share' and via AJAX the post is published to Facebook. I use the following PHP code to format the content before it is passed to the FB API:
$content = str_replace('<br>',chr(10),$content);
$content = html_entity_decode($content);
$content = strip_tags($content);
The problem is that the emojis are not showing on Facebook. When I test it with
$content = html_entity_decode('️');
Then the emoji is showing correctly, but it seems that it's not working because I get $content via AJAX/Jquery with
var content = $('#content').html();
And then pass it through AJAX.
So I suppose there is a formatting issue, but I can't wait a way to fix it..
EDIT: because the content is first shown on the page in a div, the emojis are turned into <img draggable="false" role="img" class="emoji" alt="📍" src="https://s.w.org/images/core/emoji/14.0.0/svg/1f4cd.svg">
After, my Jquery/AJAX code takes the contents of this div, so I assume it takes the above instead of the '📍'. But how can I work around this?
EDIT 2:
Passing
$content = '';
$content .= '📍 The address<br>';
$content .= '🛀 2 bathrooms<br>';
Directly to the Facebook API works and shows the emojis.
First using an other PHP function that adds the above code to a div via JQUERY/AJAX, and then getting the div's content using $('#content').html() and passing this does not work.
I found a working solution.
As I suspected, the problem was with Jquery's element.HTML(), which seems to format the data in some way.
I have now added a hidden input field, where I add and get the data via element.val() instead of element.html();
Also, to prevent the auto-formatting (perhaps caused by WordPress) of emojis into images, I have created some custom tags like {sun}, which are only replaced with their HTML codes (like ️) just before posting to Facebook.
So, I recently read this super helpful article...
http://moz.com/blog/create-crawlable-link-friendly-ajax-websites-using-pushstate
and the author outlined all of the details on how to create a website like this. However, he left out a detail that really was the most important. How to store the data in a PHP file to be called into the div defined in the jQuery. Here's a demo of the site he built...
http://html5.gingerhost.com
What I need to know is how do I create the content.php file in order to dynamically call in my content, like in the demo above?
Thanks to anyone who knows in advance...
content.php does basically returns a JSON object of keys (DOM selectors) associated with their values (HTML Code). So, if you for example want to only retrieve the main contents div, you can do something like:
<?php
$ret = array();
$contents = file_get_contents($_GET['url']);
$contents_p = explode('<div id="main" class="grid_8 alpha">', $contents);
$contents_p = explode('<div id="sidebar" class="grid_4 omega">', $contents_p[1]);
$ret['#main'] = $contents_p[0];
echo json_encode($ret);
?>
I am working on a website that i just uploaded to a test area.
http://cascarinosonline.com.216-70-85-163.messtudios.com/
I want to edit the gallery based on an incoming link. Currently I am using supersized jquery pluggin for the gallery.
When you view the gallery now its working as it should, however when you are on the Homepage and you click on "new outside area" on the bottom right corner I want it the link to take you to the gallery page but start on a different slide.
I couldn't find an easy way to do this with supersized jquery plugin... I thought it would be a simple URL anchor tag like so:
http://cascarinosonline.com.216-70-85-163.messtudios.com/gallery.php#slide12
So I think this is my solution, the default gallery page is labeled with a php value:
<?php $page = "gallery" ; ?>
And in my code it says
<?php if ($page == "gallery" ) { echo $galleryAll; } ?>
$galleryAll; has the list of gallery images in the normal order.....
Now, I made a different php code that is:
<?php if ($page == "galleryfix" ) { echo $galleryOutside; } ?>
Now this $galleryOutside; has the outside image first in the list.
Both examples above work, if I manually change the php page value to equal the content I want.
My Questions is:
I added an anchor tag to the homepage link and it looks like this:
http://cascarinosonline.com.216-70-85-163.messtudios.com/gallery.php#outside
I want php to find the url and if it has "#outside" then echo $page == "galleryOutside" else $page == "gallery"
I am not sure if this is the best way to do this, but Im pretty positive it will work as long as you can use php to get the incoming link url and change if/else value.
Thanks in advance!
-O
UPDATE: I found this, but not working.
<?php
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'cascarinosonline.com.216-70-85-163.messtudios.com/gallery.php#outside')
{
$page = "gallery";
}
else
{
$page = "galleryfix";
}
;?>
I ditched the php method, and used jquery to find the hash tag and to take the proper action inside the gallery.
if (window.location.hash == "#outside") {
$(".slide-11").addClass("activeslide");
}
I'm pretty new to programming, and i'm writing a pretty simple website for an outlet, with 4 pages: home, beauty, wellbeing, contacts.
This website will be a showroom for this outlet's articles, which will be shown in the two section of the website, depending on their area of interest.
The contractor wanted of course to be able to upload articles on his own when he wanted, so I build a simple application in php, with a login, an administration page, where he could just write Title, price, description and upload an image for the article.
All is all right, The php program is ok, uploads go smooth, the page with the articles are automatically generated by the php program, which takes the data from the mysql database, via a while cycle.
The last problem which I cannot solve, is a Slider in the homepage.
The same identical in the article's pages, have to be shown in a in home page, but not one under the other, instead they must scroll in a div, and of course the article's divs are generated by the php program.
Now, i'm not all that great in javascript, so I don't know if I'm doing it the right way, or if something's wrong with the jquery plugin I use.
The code is this:
In the header:
<script src="js/jquery.jshowoff.min.js" type="text/javascript"></script>
And in the Body:
<div id="vetrina">
<?php
include "database.php";
$connection = Database::getConnection();
$query = ("SELECT * FROM `articoli` WHERE (`importante_art` = 'si') ORDER BY `id_art` DESC");
$ris = $connection->query($query) or die (mysqli_error())
$row_cnt = $ris->num_rows;
if(($row_cnt) > 0){
$row = "";
while ($row = mysqli_fetch_array($ris)){
$id_post = $row['id_art'];
$titolo_post = stripslashes($row['titolo_art']);
$testo_post = stripslashes($row['descrizione_art']);
$immagine_post = $row['immagine_art'];
$prezzo_post = $row['prezzo_art'];
echo '<div class="evidenziato">';
echo '<h4 class="titolo_evidenziato">'.$titolo_post.'</h4>';
echo '<p class="prezzo">'.$prezzo_post.'</p>';
echo '<img class="img_evidenziato" src='.$immagine_post.'></img>';
echo '<p class="descrizione_articolo">' . $testo_post . '</p>';
echo '</div>';
}
}else{
echo "Right now there are no articles to display";
}
?>
</div>
<script type="text/javascript">
$(document).ready(function(){ $('#vetrina').jshowoff(); });
</script>
I used the showoff plugin, that should do what i want.
http://ekallevig.com/jshowoff/
I don't know what I'm doing wrong... :\
I even tried to do the slideshow without the php program, by simpli typing in the articles, but nothing.
I tried 5 different plugins.
Maybe it's just that i'm doing something wrong at the base.
Anyway, my divs come out all right, i see that they are all there, but they just wont slide...
as mentioned at http://ekallevig.com/jshowoff/ site
for jshowoff required two files.
1). the jQuery Core JavaScript Library (1.3+)
2). jquery.jshowoff.min.js
Did you used both files?.
I created a few PHP files for users of a popular hardware site to use to "Metro" their news posts. It works fairly well, you add the title of the article, links etc. and then it spits it out in Metro tile format.
Take a look: http://briandempsey.org.uk/Newstool/index.php
When the user submits, it uses the information provided to create the post. Now, I need to somehow use PHP or some other language to display the code that it generated underneath it so users can just copy and paste it. I'm not sure how to do this.
header('Content-Type: text/plain');
Since you're passing your form data using the method GET, you could instead pass it to a page that creates a url to pull the html from...
index.php will have the form as you've shown above and will post to urlCreator.php.
form.php can be deleted as it is not needed anymore, the magic will happen in the urlCreator.php file.
urlCreator.php (NEW) will have code in it like so:
<?php
// urlCreator.php will get variables passed to it from index.php
// Now create the url using the passed variables
$url = "http://briandempsey.org.uk/Newstool/form.php?title=" . $_GET['title'] . "&color=" . $_GET['color'] . "&Articlecontent=" . $_GET['Articlecontent'] //and so on to build the whole url
//Now get the pages html
$html = file_get_contents($url);
?>
Now that you have the html in a variable you can clean it using str_replace or manipulate it however you'd like.
<?php
// Still in urlCreator.php
// With the html in a variable you could now edit out the divs and echo the results
$html = str_replace("<div style=\"background-color: #008299; height: auto; width: 100%; margin-left: 10px;\">", "", $html); //removes the intro div
$html = str_replace("</div>", "", $html); //removes the closing div
//Finally echo out the html to the page for copy+paste purposes
echo $html;
?>