嗨所有只是一个简单的问题'可能非常简单'但我有一个字符串,我转换为小写来搜索文件中的字符串,但现在我需要将它在文件中找到的字符串转换回它的原始字符串。以下是我的代码
PHP
<?php
$searchfor = $_SESSION['username'];
$searchfor = strtolower($username);
// the following line prevents the browser from parsing this as HTML.
header('Content-Type: text/plain');
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents('posts/contents.php');
$contents = strtolower($contents);
#$posts = file_get_contents('posts/contents.php');
//Convert urls to <a> links
$contents = preg_replace("/([\w]+\:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/", "<a target=\"_blank\" class=\"external\" href=\"$1\">$1</a>", $contents);
//Convert hashtags to twitter searches in <a> links
$contents = preg_replace("/#([A-Za-z0-9\/\.]*)/", "<a target=\"_new\" href=\"javascript:myApp.alert('Hashtag\'s currently not working.');\">#$1</a>", $contents);
//Convert attags to twitter profiles in <a> links
$contents = preg_replace("/@([A-Za-z0-9\_\/\.]*)/", "<a href=\"profile.php?username=$1\">@$1</a>", $contents);
// escape special characters in the query
$pattern = preg_quote('@'.$searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
$day = date("l");
$time = date("h:i A");
$newDateTime = date('g:i A', strtotime($time));
$message = implode("\n", $matches[0]);
echo '<div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name">iCode Mentions</div>
<div class="facebook-date">'.$day.' at '.$newDateTime.'</div>
</div>
<div class="card-content">
<div class="card-content-inner">'.$message.'</div>
</div>
</div>';
}
else{
echo "No mentions";
}
?>
搜索字符串的文件
<div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Dummy">Dummy</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Wednesday at 11:12 AM</div>
</div>
<div class="card-content"><div class="card-content-inner">IT WORKS @ADMIN @DUMMY YES #### YES!!</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Dummy">Dummy</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Wednesday at 11:11 AM</div>
</div>
<div class="card-content"><div class="card-content-inner">Just testing auto updating notifications @Admin @Dummy</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verifiedPink.png" height="17px" width="17px"></div>
<div class="facebook-date">Wednesday at 9:09 AM</div>
</div>
<div class="card-content"><div class="card-content-inner">Testing mentions detect lowercase and uppercase @admin @Admin</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=RisingDevs">RisingDevs</a><img src="img/VerifiedBLUE.png" height="17px" width="17px"></div>
<div class="facebook-date">Wednesday at 9:09 AM</div>
</div>
<div class="card-content"><div class="card-content-inner">@Admin �</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=RisingDevs">RisingDevs</a><img src="img/VerifiedBLUE.png" height="17px" width="17px"></div>
<div class="facebook-date">Wednesday at 4:51 AM</div>
</div>
<div class="card-content"><div class="card-content-inner">@YouriOSHelper Hey bb </div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verifiedPink.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 8:02 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Testing mentions again! @Admin</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verifiedPink.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 7:58 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Just testing mentions @Admin @YourIOSHelper @cole @Vimdo @Dummy @Dummy2</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verifiedPink.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 7:43 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Hey @YourIOSHelper wud?</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verifiedPink.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 7:42 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Hey @YourIOSHelp wud?</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=YourIOSHelper">YourIOSHelper</a><img src="img/VerifiedLIGHTBLUE.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 7:40 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Hey</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 4:33 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Dear @Hdhdhddndnd you account is being suspended due to a spam name if you wish to unsuspend your account please contact me on Twitter https://twitter.com/JosephShenton_ . Sorry for any inconvenience. </div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 4:13 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Wow This App Is Just Bae am i right? XD</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 3:22 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">
@Vimdo check out http://twitter.com/JosephShenton_ #iCodeRocks
</div></div></div>
<div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=RisingDevs">RisingDevs</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 3:13 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">test</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Dummy">Dummy</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 3:05 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Just perfect love this app!</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Vimdo">Vimdo</a></div>
<div class="facebook-date">Tuesday at 2:28 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">test - @vimdo_</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 2:16 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Yes I finally got posts to show up in order of date!</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 2:16 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Ter</div></div>
</div> <div class="card facebook-card">
<div class="card-header no-border">
<div class="facebook-name"><a href="profile.php?username=Admin">Admin</a><img src="img/verified.png" height="17px" width="17px"></div>
<div class="facebook-date">Tuesday at 2:16 PM</div>
</div>
<div class="card-content"><div class="card-content-inner">Test</div></div>
</div>
现在我真的希望有一种方法可以将所有转换回原来的套管
感谢Joseph Shenton:)
答案 0 :(得分:1)
$contents = file_get_contents('posts/contents.php');
$var = $chontents; //before anything happen to it
$contents = strtolower($str); //after changing to lowercase
你可以使用$ var,因为它没有被任何东西改变