I'm trying to take the currently logged in user id on my website and add it to the end of the URL to display in an iframe (iframe is for a third party website)
I have stumbled upon this code;
function makeClickableLink($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9#:%_\+.~#?&//=]+)', '\\1', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9#:%_\+.~#?&//=]+)', '\\1\\2', $text);
return $text;
}
$user_id = get_current_user_id(); // getting current user id from wordpress
$text = "http://example.com/something/something/?ba=310139&gd=927691&sid=$user_id"; // that's the link to a website i'm trying to iframe with my $user_id at the end
echo makeClickableLink($text);
http://example.com/something/something/?ba=310139&gd=927691&sid=1
So this code outputs the link that I put into the $text and replaces $user_id with the currently logged in users id which is so far exactly what I'm looking for.
Now.. Is there a way to iframe this link by modifying the above code ? (i have a plugin that allows me to use the iframe tags in wordpress before someone mentions that i can't use it there) Or another different way to do it? I need the above URL but in an iframe. I'm sure this is fairly easy to do however I cannot wrap my head around it (very new to all this but trying my best to learn :))
Any help would be greatly appreciated! Thanks!
Related
i want to make a social media audit tool and i want to get likes of a person's Fb page. Basically what i want is i want that person to enter his FB pages URL and then i want to fetch the likes of his page and echo it in my PHP page. Is there any way I can do that without using graph API or any API. I just want a simple piece of code.
I have searched many questions regarding my project on web and on StackOverflow as well but coudn't find what i wanted, at last, I am asking this question. Is there anyone who can help me regarding this?
Thanx in advance.
<?php
$file = "https://www.facebook.com/IntellectualIndies/?epa=SEARCH_BOX";
$data = file_get_contents($file);
preg_match_all ('~<div class=\'_4bl9\'>\s*(<div.*?</div>\s*)?(.*?)</div>~is', $data, $matches);
$content = $matches[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."<br />";
}
?>
i tried this code.
Is there any way I can do that without using graph API or any API
No, scraping is not allowed on Facebook.
There is only one way to do this:
Apply for Page Public Content Access
Use the Graph API with the following endpoint/field: /page-id?fields=fan_count
API Reference with example code: https://developers.facebook.com/docs/graph-api/reference/page/
I'm looking for php code or function which can help me to search and find first matching URL, based on specific pattern, from a wordpress post and echo the same url in the same post where it's necessary instead of modifying parent url.
Example Case:
URL:https://example.com/education_system_comparison.html
when I open this page, afer title of the post, there is description of this post, here I want to search from description to find matching url that must starts from my desired domain name like https://some-url-is-here/3978732978937298.html and ends with .html
If anyone here can help me to create a function or use any filters those can work with wordpress or php, it would be so helping and must appreciated. Thank you so much.
I found the solution what I was looking for and it's working perfectly fine on single post or on custom page.
Here is function, I've added in functions.php of my WordPress theme;
function getBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return ''; }
so I can call above function by using following code and it work 100% fine, example code:
<?php
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$start = ' https://some-url-is-here/';
$end = '"';
$output = getBetween($content,$start,$end);
echo $start.$output; ?>
It gives output like below based on first matching url and stop immediately
https://some-url-is-here/3978732978937298.html
On the other hand, once I applied the same code throughout my website so I can get every matching url from each and every published post to use it where necessary on the same post. As I save changes, my server got halted coz there were hundreds of httpd requests started processing and server went down immediately.
I'm not sure what exactly is going wrong here, If anyone can guide me and help me what exactly wrong here so it'll be much appreciated and any suggestion or fix, Thanks.
I am creating a website on Joomla and want to have a private page for each individual user. If anyone knows of the best way to do this apart from giving each individual their own group, this is the way I would like to try:
I want to create a page where php will match a file name based on the user id of the logged in user. This is the code I have so far:
<?php
$user = JFactory::getUser();
$user_id = $user->id;
$profilepage = file_get_contents ("user" + $user_id +"file.txt");
echo $profilepage;
?>
This gives me the user id in a variable, and I would like for the correct profilepage to show. For example, if User594 is logged in, then I want the file to be used for $profilepage to be "user" + 594 + "file.txt"...for an actual file name of user594file.txt. Is this possible? Or is there a correct way of doing this?
Thanks for any help!
Since you probably chose not to delete your question and not hearing from you in comment in regards to a comment to you, I decided to post my comment as an answer.
You're presently wanting to use + signs. This isn't the character to use in order to concatenate.
In PHP, you need to use dots/periods:
$profilepage = file_get_contents ("user" . $user_id ."file.txt");
Good evening...Am a newbie to programming and I was able to work my way round getting url in text to display as link using the codes below
<?php
$textorigen = $row_get_tweets['tweet'];
// URL starting with http://
$reg_exUrl = "/(^|\A|\s)((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\/\S*)?)/";
if(preg_match($reg_exUrl, $textorigen, $url)) {
// make the urls hyper links
$text_result=preg_replace( $reg_exUrl, "$1$2 ", $textorigen );
echo $textorigen=$text_result;
} else {
// if no urls in the text just return the text
echo $text_result=$textorigen;
}
// URL starting www.
$reg_exUrl = "/(^|\A|\s)((www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\/\S*)?)/";
if(preg_match($reg_exUrl, $text_result, $url)) {
// make the urls hyper links
$text_result=preg_replace( $reg_exUrl, "$1$2", $text_result );
echo $textorigen=$text_result;
?>
So Its works fine but duplicates my post if its the second if statement found true i.e (www.anything.com) and If there's a post without a link it doesnt display it.Am very sure its my if statement that is wrong and have spent hours trying to fix it..Kindly help me.
I want it to :
1) Display a www link if posted
2) Display a http link if posted
3) Display the link if no htto or www is posted..Thanks
Kindly note the preg_replace function works perfectly well
The problem is that every time the program reaches echo, the post gets printed again.
So my suggestion is to change all echo $textorigen=$text_result; to just $textorigen=$text_result;, and at the very end of the all the replacement logic put echo $textorigen;.
I'm currently using this code:
$blog= file_get_contents("http://powback.tumblr.com/post/" . $post);
echo $blog;
And it works. But tumblr has added a script that activates each time you enter a password-field. So my question is:
Can i remove certain parts with "file_get_contents"?
Or just remove everything above
anything will work!
Thank you for your help!
(could i possibly kill a whole div so it wont load at all?)
You could try something like this, assuming the div you are trying to remove has a specific id and/or class:
$blog= file_get_contents("http://powback.tumblr.com/post/" . $post);
$blog = preg_replace('!<div\s+id="div-id"\s+class="div-class">.*?</div>!is', '', $blog);
echo $blog;
The post I found this in (http://stackoverflow.com/questions/1114916/how-can-i-remove-an-html-element-and-its-contents-using-regex) notes that if there is a nested div, this will fail.
Regardless, preg_replace or regex is your best bet here.