My xpath query string doesn´t work - html-parsing

I would like to grab the following value on this website with xquery. After trying for awhile I couldn't figure it out. Here is what I am trying to fetch (image link)
And the code I tried using:
$xpath = new DOMXPath( $html );
$nodelist = $xpath->query( "???????????????" );
Any ideas?

You can try to grep the value between script tags
Like
//form/div/div/div[#class="values span-7"]/skipt/Text()
After parse the value in PHP other language hat you use to get your string

Can you get the value off of the input?
//form//input[#name="val7"]/#value
Update:
You can get the stuff in the script tag, but that's as far as you can get using xpath. You'll then need to parse the contents of the script tag in order to get that value.
//form[#id="werte"]//div[#class="calval7"]//div[#class="values"][1]/script/text()

Related

Change youtube shortened url value in iframe

I am using advanced custom filed wordpress plugin to create a meta tag called youtube URL...
When some one put the video url in shorter format like this https://youtu.be/H-30B0cqh88
Then the iframe I put to show the video doesn't work cause iframe doesn't work with shorter version of url
rather it needs real url as a source.. My iframe code is as below
">
How can I achive this.. Let me show you how I want to achieve this..
I am not that expert on php so please give me the full working code..
<?php
the_field("listing_video_1") == $got_url_from_user_input
if $got_url_from_user_input == https://youtu.be/H-30B0cqh88 in this format
$actual_URL= replace above url to https://youtube.com/embed/H-30B0cqh88
?>
How can I achieve this please.
Thanks in advance
Here's a simple way to use preg_replace to accomplish what you are trying to do:
<?php
// SET OUR DEFAULT URL
$got_url_from_user_input = 'https://youtu.be/H-30B0cqh88';
print "\nSTARTING URL: ".$got_url_from_user_input;
// DO THE REPLACE AND PRINT OUT THE FINAL RESULT
$actual_URL = preg_replace('~https://youtu\.be/([-A-Z0-9]+)~i', 'https://youtube.com/embed/$1', $got_url_from_user_input);
print "\nFINAL URL: ".$actual_URL;
There's not much magic here, so let me run down it quickly:
https://youtu\.be/ - Look for this pattern exactly. We escape the dot with a backslash so it finds a literal dot and not any character.
([-A-Z0-9]+) - This is just your basic character class matching any dash, letter or number, occurring at least one time. We put it in parenthesis so that we it will be saved in $1 and we can plug it into our final url.
Here is the above code in a working demo you can take a look at:
http://ideone.com/zECA2e
You can just use php str_replace() function as in following code :
<?php
$actual_url = str_replace('https://youtu.be/', 'https://www.youtube.com/embed/', $got_url_from_user_input);
echo $actual_url;
?>
str_replace() will replace youtubes short url with embade url.

YouTube video API not working with IDs beginning with a dash

I am accessing data from YouTube's API, I have everything working fine but the problem I'm having is that when there's a dash (-) at the beginning of the videoID that it's not returning the json data.
$videoID = -FIHqoTcZog;
$json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/videos?q={$videoID}&alt=json"));
I am however able to return the thumbnail as always with it using this:
$thumbnail = "http://i4.ytimg.com/vi/".$videoID."/mqdefault.jpg";
This is the code that I use to pull the information from the above json that I want.
$title = $json->{'feed'}->{'entry'}[0]->{'title'}->{'$t'};
$description = $json->{'feed'}->{'entry'}[0]->{'media$group'}->{'media$description'}->{'$t'};
$thumbnail = "http://i4.ytimg.com/vi/".$videoID."/mqdefault.jpg";
$ratings = ((round($json->{'feed'}->{'entry'}[0]->{'gd$rating'}->{'average'}, 1)/$json->{'feed'}->{'entry'}[0]->{'gd$rating'}->{'max'})*100)."%";
$views = number_format($json->{'feed'}->{'entry'}[0]->{'yt$statistics'}->{'viewCount'});
$duration = $json->{'feed'}->{'entry'}[0]->{'media$group'}->{'yt$duration'}->{'seconds'};
Are you sure you're only getting a problem with IDs that have a dash in front of it? The code you pasted shouldn't be working with any Youtube ID, because the gdata feed returns, as part of the JSON, some text with the '$' character in it. That character is a PHP identifier, so you'll get 500 errors trying to run the json_decode function on whatever the feed returns.
One way to solve the problem is to use json_decode's 2nd parameter to give you an associative array rather than an object, like this:
$json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/videos?q={$videoID}&alt=json"),true);
Of course, that requires you to work with an array, too, but the subsequent code changes should be minimal.
If you aren't getting errors with other videos using the exact same code, perhaps you could post it here?

How do you include hashtags within Twitter share link text?

I'm writing a site with a custom tweet button that uses the www.twitter.com/share function, however the problem I am having is including hash '#' characters within the tweet text.
For example:
http://www.twitter.com/share?url=www.example.com&text=I+am+eating+#branstonpickel+right+now
The tweet text comes out as 'I am eating' and omits the hash and everything after.
I had a quick look on the Twitter forums and learnt the hash '#' character cannot be part of the share url. On https://dev.twitter.com/discussions/512#comment-877 it was said that:
Hashes are special characters in the URL (they identify document fragments) so they, and anything following, does not get sent the server.
and
you need to URLEncode it, so use %23
When I tried the 2nd point in my test link:
www.twitter.com/share?url=www.example.com&text=I+am+eating+%23branstonpickel+right+now
The tweet text came out as 'I am eating %23branstonpickel right now' literally including %23 instead of converting it to a hash.
Sorry for the waffely question, but does anyone know what it is I'm doing wrong?
Any feedback would be greatly appreciated :)
It looks like this is the basic setup:
https://twitter.com/intent/tweet?
url=<url to tweet>
text=<text to tweet>
hashtags=<comma separated list of hashtags, with no # on them>
This would pre-built a tweet of: <text> <url> <hashtags>
The above example would be:
https://twitter.com/intent/tweet?url=http://www.example.com&text=I+am+eating+branston+pickel+right+now&hashtags=bransonpickel,pickles
There used to be a bug with the hashtags parameter... it only showed the first n-1 hashtags. Currently this is fixed.
you can use %23 instead of hash (#) in url eg
http://www.twitter.com/share?url=www.example.com&text=I+am+eating+%23branston+%23pickel+right+now
I may be wrong but i think the hashtag has to be passed as a separate variable that will appear at the end of your tweet ie:
http://www.twitter.com/share?url=www.example.com&text=I+am+eating+branston+pickel+right+now&hashtag=bransonpickel
will result in "I am eating branston pickel right now #branstonpickle"
On a separate note, I think pickel should be pickle!
Cheers
Toby
use encodeURIComponent to encode the url
If you're using PHP, you can use the following:
<?php echo 'http://www.twitter.com/share?' . http_build_query(array(
'url' => 'http://www.example.com',
'text' => 'I am eating #branstonpickel right now'
)); ?>
This will do all the URL encoding for you, and it's easy to read.
For more information on the http_build_query, see the PHP manual:
http://us2.php.net/http_build_query
For url with line jump, # , # and special unicode in it, the following works :
var lineJump = encodeURI(String.fromCharCode(10)),
hash = "%23", arobase="%40",
tweetText = 'https://twitter.com/intent/tweet?text=Le signe chinois '+hans+' '+item.pinyin+': '+item.definition.replace(";",",")+'.'
+lineJump+'Merci '+arobase+'Inalco_Officiel '+arobase+'CRIparis ❤️🇨🇳 '
+lineJump+hash+'Chinois '+hash+'MOOC'
+lineJump+'https://hanzi.cri-paris.org/',
tweetTxtUrlEncoded = tweetText+ "" +encodeURIComponent('#'+lesson+encodeURIComponent(hans));
urlencode
https://twitter.com/intent/tweet?text=<?= urlencode("I am eating #branstonpickel right now"); ?>"
You can just use this code and modify it
20% means space
23% means hashtag
In JS you can easily encode the special characters using encoreURIComponent.
(Warning: don't use encodeURI as "#" and "#" are not escaped.)
Here's an example with mention and hashtag:
const text = "Hello #world ! Go follow #StackOverflow";
const tweetUrl = `https://twitter.com/intent/tweet?text=${ encodeURIComponent(text) }`;

Call javascript in sharepoint custom field

I am creating a custom field in SharePoint 2007. I have seen other solutions where the current site URL was default value of a text field.
How can I get this current site URL?
I have got one answer whiches states that I shall use JavaScript, but where do I put the script?
I hope you can help.
BR
To answer 1
I am new to SharePoint and am not quiet sure where to put the java script. Normaly i just give the initial value to the field in the FieldEditor.cs file but how can I do this with the javascript?
Here follows a picute of my files.
I have tried to put it into FiledEditor.cs but this results in the value of myString is written in the top of the web page.
Here is my current code:
string myScript = "var currentUrl = document.URL; LabelLookupFieldTargetURLText.Text = currentUrl;";
Page.ClientScript.RegisterClientScriptBlock(LabelLookupFieldTargetURLText.GetType(), "LabelLookupFieldTargetURLTextJavaScript", myScript);
I found the answer my self. I don't need to use a java script. I can just use SPContext.Current.Site.Url
use javascript:
var nowUrl = document.URL;
yourTextfiled.value = nowUrl;
you can read this:http://www.w3schools.com/jsref/dom_obj_document.asp

jQuery autocomplete not displaying my encoded values

I am working from this example: http://jqueryui.com/demos/autocomplete/#remote and I am encoding the output like this:
$rows = array();
while($r = mysql_fetch_assoc($category_result))
{
$rows[] = $r;
error_log ("rows: ".$rows[0]);
}
echo json_encode($rows);
But the dropdown on the other side shows nothing. Here is my test page: http://problemio.com/test.php - if you enter "ho" it matches 2 results in the database, but they are not getting displayed for some reason. Any idea why?
Thanks!!
The properties should be named label and value. From the JQuery UI demo page you linked to:
The local data can be a simple Array of Strings, or it contains
Objects for each item in the array, with either a label or value
property or both. The label property is displayed in the suggestion
menu.
So you would need to rename category_name to label either in PHP or later on in your JavaScript source handler function. The latter would require you to replace the PHP URL with a callback function like in the remote example. That way you could get the data any way you want (e.g. by jQuery.getJSON()) and work with it before it gets handed over to the suggestion box.
Hope this helps.
Regarding your comment, this should do it:
$rows = array();
while ($r = mysql_fetch_array($category_result)) {
$rows[] = array("label" => $r["category_name"]);
}
echo json_encode($rows);

Resources