-
1. Re: Searching/Replacing Large Chunks of Code via PHP
Nancy O. Jun 9, 2014 11:08 AM (in response to jyeager11)I guess I'm missing something important because each page needs a unique page title for SEO reasons. If you globally replace existing titles with a generic one, you're shooting yourself in the foot with Google and other SEs.
Maybe what you're trying to do is echo contents of your title variable into a page heading, something like this?
<title><?php $title="NEW PAGE TITLE"; ?><?php echo $title ; ?></title>
</head>
<body>
<h3><?php echo $title ; ?></h3>
Nancy O.
-
2. Re: Searching/Replacing Large Chunks of Code via PHP
bregent Jun 9, 2014 11:26 AM (in response to jyeager11)It might help if you explain why do you need static content if it's going to be replaced with dynamic content? Why not just always have it dynamic? It would also help to see the entire code you are working with.
-
3. Re: Searching/Replacing Large Chunks of Code via PHP
jyeager11 Jun 9, 2014 11:33 AM (in response to Nancy O.)Your heart's in the right place, but I'm really just trying to learn how to replace (or remove) large chunks of text on the fly via PHP. I only used it because it was an easy example of a short tag that's usually unique in a web page source code.
Let's say I want to remove an entire portion of text non-destructively, as it's being served to the end user. For instance, a specific javascript. There's a 50-line javascript in my web page that I want removed or replaced non-destructively. Rather than str_replace() the entire code with "", I was told that using explode() to divide the sections I want to affect into 3 (starting marker, middle, end marker) so that if something changed in the middle area later on, the entire section will still get recognized by the PHP commands looking to re-write it on the output.
Normally, a javascript would begin with <script type="text/javascript"> and end with </script>. But I can't target that lone (like I did <title></title>) because there will be several instances of both <script type="text/javascript"> and </title> in the page and I only want to affect one of them.
This means I'll have to quote more code in my markers to make sure they're unique.
In other words, how do I do this...
$markerBegin = "
<script type=\"text/javascript\">
function pmc_ads_interruptus_single() {
"...and have it working? Right now, it's not recognizing those 2 lines in the code. But they're there. There's something wrong with my syntax.
I did think to escape the quotation marks with backslashes, but is there anything else I need to re-interpret for the server to recognize what I'm targeting? For instance, is there an "escape" code for line breaks too? Do I need to add something between \"> and function for those two lines to be recognized when PHP instructs the page to look for them?
-
4. Re: Searching/Replacing Large Chunks of Code via PHP
bregent Jun 9, 2014 11:40 AM (in response to jyeager11)



